Collection of PSR-20 clocks
The best way to install Clock is via Composer. Just add konecnyjakub/clock to your dependencies.
This clock returns current time. It uses default timezone in PHP by default but it is possible to set a different one.
<?php
declare(strict_types=1);
use DateTimeZone;
use Konecnyjakub\Clock\SystemClock;
(new SystemClock())->now();
(new SystemClock(new DateTimeZone("Europe/Prague")))->now();
This clock always returns set time which makes it useful for tests.
<?php
declare(strict_types=1);
use DateTimeImmutable;
use Konecnyjakub\Clock\FrozenClock;
(new FrozenClock(new DateTimeImmutable("1970-01-01")))->now();
This clock return current time in UTC.
<?php
declare(strict_types=1);
use DateTimeImmutable;
use Konecnyjakub\Clock\UTCClock;
(new UTCClock())->now();