Provides a simple abstraction of a clock.
Switch branches/tags
Nothing to show
Clone or download
localheinz Merge pull request #32 from localheinz/feature/synchronize
Enhancement: Synchronize project tooling configuration with localheinz/repository
Latest commit c2217d0 Dec 11, 2018

README.md

clock

Build Status codecov Latest Stable Version Total Downloads

Provides a simple abstraction of a clock, following the suggestion by Martin Fowler.

Installation

Run

$ composer require localheinz/clock

Usage

SystemClock

Create a new system clock and use it to determine the current time:

use Localheinz\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:

use Localheinz\Clock;

$now = new \DateTimeImmutable();

$clock = new Clock\FrozenClock($now);

sleep(5);

$stillNow = $clock->now();

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.

Credits

This project is inspired by lcobucci/clock (originally licensed under MIT by Luís Cobucci), with additional support for PHP 7.0.