PHP code example of getwarp / clock

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

    

getwarp / clock example snippets


use Warp\Clock\DateTimeImmutableValue;

$time = DateTimeImmutableValue::now();
// $time = DateTimeImmutableValue::from('2020-02-02 20:22:02');
// $time = DateTimeImmutableValue::from(3 * DateTimeImmutableValue::HOUR); // now + 3 hours

\assert($time instanceof \DateTimeImmutable);

echo (string)$time;
// 2020-02-02 20:22:02
echo \json_encode($time);
// 2020-02-02T20:22:02+00:00

use Warp\Clock\FrozenClock;
use Warp\Clock\SystemClock;

$clock = new FrozenClock(SystemClock::fromUTC());
$startedAt = $clock->now();
\sleep(5);
$finishedAt = $clock->now();
\assert($startedAt === $finishedAt);

$clock->reset();