ergebnis / clock
Provides a simple abstraction of a clock.
Installs: 381 236
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.16.0
- ergebnis/license: ^1.1.0
- ergebnis/php-cs-fixer-config: ~3.2.1
- ergebnis/test-util: ^1.5.0
- infection/infection: ~0.25.3
- phpunit/phpunit: ^9.5.10
- psalm/plugin-phpunit: ~0.16.1
- vimeo/psalm: ^4.13.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.