PHP code example of dgame / php-time

1. Go to this page and download the library: Download dgame/php-time library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dgame / php-time example snippets


seconds(300)->inMinutes()->equalsAmount(5);

minutes(60)->inSeconds()->equalsAmount(3600);
minutes(60)->inHours()->equalsAmount(1);

hours(24)->inMinutes()->equalsAmount(1440);
hours(24)->inDays()->equalsAmount(1);

days(7)->inHours()->equalsAmount(168);
days(7)->inWeeks()->equalsAmount(1);

weeks(12)->inDays()->equalsAmount(84);

months(12)->inYears()->equalsAmount(1);

years(1)->inWeeks()->equalsAmount(52);
years(2)->inMonths()->equalsAmount(24);

hours(24)->equals(days(1));
days(1)->equals(hours(24));
years(1)->equals(days(365));
weeks(1)->equals(days(7));

days(1)->add(hours(24))->equals(days(2));
hours(24)->subtract(days(0.5))->equals(hours(12));
hours(1)->equals(minutes(60));

Month::Of('Feb', 2015)->inDays()->equalsAmount(28);
Month::Of('Feb', 2015)->inWeeks()->equalsAmount(4);
Month::Of('Feb', 2016)->inDays()->equalsAmount(29);
Month::Of('Jun', 2016)->inDays()->equalsAmount(30);
Month::Of('Jun', 2016)->inWeeks()->equalsAmount(4.28571);

Year::Of(2016)->isLeapyear();
Year::Of(2015)->inDays()->equalsAmount(365);
Year::Of(2016)->inDays()->equalsAmount(366);
Year::Of(2015)->inWeeks()->equalsAmount(52.142857142857);
Year::Of(2016)->inWeeks()->equalsAmount(52.285714285714);

$unit = new TimeUnits(days(1000));

$this->assertTrue($unit->getYears()->equalsAmount(2));
$this->assertTrue($unit->getMonths()->equalsAmount(8));
$this->assertTrue($unit->getWeeks()->equalsAmount(3));
$this->assertTrue($unit->getDays()->equalsAmount(5));
$this->assertTrue($unit->getHours()->equalsAmount(11));
$this->assertTrue($unit->getMinutes()->equalsAmount(33));
$this->assertTrue($unit->getSeconds()->equalsAmount(20));

$unit = new TimeUnits(hours(4.5));

$this->assertTrue($unit->getYears()->equalsAmount(0));
$this->assertTrue($unit->getMonths()->equalsAmount(0));
$this->assertTrue($unit->getWeeks()->equalsAmount(0));
$this->assertTrue($unit->getDays()->equalsAmount(0));
$this->assertTrue($unit->getHours()->equalsAmount(4));
$this->assertTrue($unit->getMinutes()->equalsAmount(30));
$this->assertTrue($unit->getSeconds()->equalsAmount(0));

$unit = new TimeUnits(minutes(525));

$this->assertTrue($unit->getYears()->equalsAmount(0));
$this->assertTrue($unit->getMonths()->equalsAmount(0));
$this->assertTrue($unit->getWeeks()->equalsAmount(0));
$this->assertTrue($unit->getDays()->equalsAmount(0));
$this->assertTrue($unit->getHours()->equalsAmount(8));
$this->assertTrue($unit->getMinutes()->equalsAmount(45));
$this->assertTrue($unit->getSeconds()->equalsAmount(0));