PHP code example of palmtree / chrono

1. Go to this page and download the library: Download palmtree/chrono 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/ */

    

palmtree / chrono example snippets



use Palmtree\Chrono\Date;

$date = new Date('2019-01-01');

$date->format('d/m/Y');

$anotherDate = new Date('2019-02-01');

$date->isSame($anotherDate, 'year'); // returns true
$date->isSame($anotherDate, 'month'); // returns true
$date->isSame($anotherDate, 'day'); // returns false

$date->isBefore($anotherDate); // returns true
$date->isAfter($anotherDate); // returns false

// returns true if the date object represents the current date
$date->isToday();


use Palmtree\Chrono\Date;

$date = new Date('2019-01-01');

$date->add(10, 'day');

$date->format('Y-m-d'); // returns '2019-01-11'

$date->subtract(1, 'month');

$date->format('Y-m-d'); // returns '2018-12-11'


use Palmtree\Chrono\Time;

$time = new Time('13:00:03');

$time->format('H:i');

$anotherTime = new Time('13:02:01');

$time->isSame($anotherTime, 'hour'); // returns true
$time->isSame($anotherTime, 'minute'); // returns false

$time->isBefore($anotherTime); // returns true
$time->isAfter($anotherTime); // returns false


use Palmtree\Chrono\Time;

$time = new Time('13:00:00');

$time
    ->add(1, 'hour')
    ->add(30, 'minute')
    ->add(15, 'second');

$time->format('H:i:s'); // returns '14:30:15'

$time->subtract(15, 'second');

$time->format('H:i:s'); // returns '14:30:00'


use Palmtree\Chrono\DateTime;

$dateTime = new DateTime('2019-01-01 12:30:00');

$dateTime->format('d/m/Y H:i'); // returns 01/01/2019 12:30

$anotherDateTime = new DateTime('2019-01-01 12:30:01');

$dateTime->isSame($anotherDateTime); // returns false
$dateTime->isSame($anotherDateTime, 'day'); // returns true
$dateTime->isSame($anotherDateTime, 'hour'); // returns true
$dateTime->isSame($anotherDateTime, 'minute'); // returns true

$dateTime->isBefore($anotherDateTime); // returns true
$dateTime->isAfter($anotherDateTime); // returns false


use Palmtree\Chrono\Date;

$jan = new Date('2019-01-01');
$feb = new Date('2019-02-01');
$march = new Date('2019-03-01');

$minDate = Date::min($jan, $feb, $march);

return $minDate === $jan; // returns true;


use Palmtree\Chrono\Date;

$jan = new Date('2019-01-01');
$feb = new Date('2019-02-01');
$march = new Date('2019-03-01');

$maxDate = Date::max($jan, $feb, $march);

return $maxDate === $march; // returns true;


use Palmtree\Chrono\Date;

$dates = [new Date('2019-01-01'), new Date('2019-02-01')];

$minDate = Date::min(...$dates);

return $minDate === $dates[0]; // returns true;