Collection of PSR-20 clocks

1.0.0 2024-09-15 13:45 UTC

This package is auto-updated.

Last update: 2024-10-15 15:54:02 UTC


README

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