ebene7 / php-clock
E7 PHP clock
Installs: 21
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/ebene7/php-clock
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 6.5.6
This package is auto-updated.
Last update: 2025-10-22 16:18:02 UTC
README
Provides a simple abstraction of a clock, following the suggestion by Martin Fowler.
Installation
Package is available on Packagist, you can install it using Composer.
$ composer require ebene7/php-clock
Basic usage
SystemClock
Create a SystemClock object and simply use it! Object that will return the current time based on the given timezone
<?php use E7\Clock\SystemClock; $clock = new SystemClock(); $now = $clock->now();
It's also possible to set the timezone.
<?php use DateTimeZone; use E7\Clock\SystemClock; $timezone = new DateTimeZone('Europe/Berlin'); $clock = new SystemClock(timezone); $now = $clock->now();
FrozenClock
The FrozenClock simplfies testing and it's also esy to use. The FrozenClock object always returns a fixed time object.
<?php use DateTimeImmutable; use E7\Clock\FrozenClock; $now = new DateTimeImmutable(); $clock = new FrozenClock($now); $now = $clock->now();
Credits
This project is inspired by lcobucci/clock (originally licensed under MIT by Luís Cobucci).