Skip to content
Provides a simple abstraction of a clock.
PHP Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.dependabot
.github
src
test
.editorconfig
.gitattributes
.gitignore
.php_cs
CHANGELOG.md
LICENSE
Makefile
README.md
composer.json
composer.lock
infection.json
phpstan-baseline.neon
phpstan.neon
psalm-baseline.xml
psalm.xml

README.md

clock

Continuous Deployment Continuous Integration Code Coverage Type Coverage Latest Stable Version Total Downloads

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();

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.

Credits

This project is inspired by lcobucci/clock (originally licensed under MIT by Luís Cobucci).

You can’t perform that action at this time.