PHP code example of withinboredom / time

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

    

withinboredom / time example snippets


use Withinboredom\Time;
use Withinboredom\Time\Unit;

$hour = Time::from(Unit::Hours, 1);
$minutes = Time::from(Unit::Minutes, 60);

echo $hour === $minutes ? 'true' : 'false'
// outputs: true

function sleep(Time $time): void {
    \sleep($time->as(Unit::Seconds));
}

// Helper functions are 

// use the hour constant to get one hour
$hour = Hour;

$hour = $hour->multiply(10)->add(Minutes(10)); // get 10:10 hours

$interval = $hour->toDateInterval();

echo Hours(10) < $hour ? 'true' : 'false';
// output: true

class CacheItem {
    public function __construct(
        #[Field('expiration_in_seconds')]
        #[TimeAs(Unit::Seconds)]
        public Time $expiration,
    ) {}
}

$serde = new SerdeCommon(handlers: new \Withinboredom\Time\SerdeExporter());
$serde->serialize(new CacheItem(Minutes(5)), 'json');