PHP code example of crutch / clock-dev
1. Go to this page and download the library: Download crutch/clock-dev 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/ */
crutch / clock-dev example snippets
$format = 'Y-m-d\TH:i:sp';
$clock = new \Crutch\DevClock\ClockWaited(
new DateTimeZone('UTC'),
DateTimeImmutable::createFromFormat($format, '2022-01-01T00:00:00Z')
);
var_dump($clock->now()->format($format)); // "2022-01-01T00:00:00Z"
$clock->wait(5);
var_dump($clock->now()->format($format)); // "2022-01-01T00:00:05Z"
$clock->wait(300);
var_dump($clock->now()->format($format)); // "2022-01-01T00:05:05Z"
$format = 'Y-m-d\TH:i:sp';
$timer = new \Crutch\DevClock\ClockSequence(
DateTimeImmutable::createFromFormat($format, '2022-01-01T00:00:00Z'),
new \Crutch\DevClock\Sequence\HardIntervalSequence(5),
new DateTimeZone('UTC')
);
var_dump($timer->now()->format($format)); // "2022-01-01T00:00:00Z"
var_dump($timer->now()->format($format)); // "2022-01-01T00:00:05Z"
var_dump($timer->now()->format($format)); // "2022-01-01T00:00:10Z"
var_dump($timer->now()->format($format)); // "2022-01-01T00:00:15Z"
var_dump($timer->now()->format($format)); // "2022-01-01T00:00:20Z"