quillstack/clock

A clock based on PSR-20: Clock, with one which stands still for tests.

Maintainers

Package info

github.com/quillstack/clock

Homepage

pkg:composer/quillstack/clock

Transparency log

Statistics

Installs: 197

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v0.6.0 2026-08-21 20:53 UTC

This package is auto-updated.

Last update: 2026-08-23 00:22:18 UTC


README

Tests Latest Version Downloads PHP Version StyleCI CodeFactor Quality Gate Coverage Maintainability Reliability Security License

A clock based on PSR-20: Clock, with one which stands still for tests.

Installation

composer require quillstack/clock

Usage

Anything deciding when something happened, or whether it has expired, takes a clock rather than reading the wall clock where it stands. SystemClock is that wall clock:

use Quillstack\Clock\SystemClock;

$cache = new ArrayCache(new SystemClock());

FrozenClock stands still until it is moved, so a test watches something expire without waiting for it:

use Quillstack\Clock\FrozenClock;

$clock = new FrozenClock();
$cache = new ArrayCache($clock);

$cache->set('key', 'value', 60);
$clock->sleep(61);

$cache->get('key'); // null

It is in the sources rather than the tests, because anything taking a clock will want it.

Tests

composer test

License

MIT. See LICENSE.