ergebnis / clock
Provides a simple abstraction of a clock.
Installs: 513 435
Dependents: 1
Suggesters: 0
Security: 0
Stars: 31
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- psr/clock: ^1.0.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.28.3
- ergebnis/license: ^2.0.0
- ergebnis/php-cs-fixer-config: ~4.11.0
- infection/infection: ~0.26.6
- phpunit/phpunit: ^9.5.26
- psalm/plugin-phpunit: ~0.18.3
- vimeo/psalm: ^4.30.0
Provides
- psr/clock-implementation: 1.0.0
README
Provides a simple abstraction of a clock, following the suggestion by Martin Fowler.
Installation
Run
$ composer require ergebnis/clock
Usage
SystemClock
Create a new system clock and use it to determine the current time:
<?php use Ergebnis\Clock; $timeZone = new \DateTimeZone('Europe/Berlin'); $clock = new Clock\SystemClock($timeZone); $now = $clock->now();
FrozenClock
Create a new frozen clock and use it in tests:
<?php use Ergebnis\Clock; $now = new \DateTimeImmutable(); $clock = new Clock\FrozenClock($now); sleep(5); $stillNow = $clock->now();
Alternatively, create a new frozen clock by freezing a system clock:
<?php use Ergebnis\Clock; $timeZone = new \DateTimeZone('Europe/Berlin'); $clock = new Clock\SystemClock($timeZone); $frozenClock = $clock->freeze(); $now = $clock->now(); sleep(5); $stillNow = $clock->now();
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Credits
This project is inspired by lcobucci/clock
(originally licensed under MIT by Luís Cobucci).
Curious what I am building?
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.