Skip to content

Collection of PSR-20 clocks

License

Notifications You must be signed in to change notification settings

konecnyjakub/clock

Repository files navigation

Clock

Total Downloads Latest Stable Version build status coverage report License

Collection of PSR-20 clocks

Installation

The best way to install Clock is via Composer. Just add konecnyjakub/clock to your dependencies.

Usage

System clock

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();

Frozen clock

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();

UTC clock

This clock return current time in UTC.

<?php
declare(strict_types=1);

use DateTimeImmutable;
use Konecnyjakub\Clock\UTCClock;

(new UTCClock())->now();