A PHP 7 clock interface.

1.0.0 2017-12-23 11:59 UTC

This package is auto-updated.

Last update: 2024-10-29 05:22:23 UTC


README

A PHP 7 clock interface.

Build Status Version

Installation

Through Composer, obviously:

composer require chrisharrison/clock

Examples

Frozen clock (useful for testing)

$frozenClock = new \ChrisHarrison\Clock\FrozenClock(new \DateTime('1988-05-01 16:00:00'));
echo $frozenClock->now()->format('Y-m-d H:i:s');
echo $frozenClock->now()->format('Y-m-d H:i:s');
echo $frozenClock->now()->format('Y-m-d H:i:s');

Outputs:

1988-05-01 16:00:00
1988-05-01 16:00:00
1988-05-01 16:00:00

System clock (has a hard dependency on the underlying operating system's clock)

$systemClock = new \ChrisHarrison\Clock\SystemClock;
echo $systemClock->now()->format('Y-m-d H:i:s');
echo $systemClock->now()->format('Y-m-d H:i:s');
echo $systemClock->now()->format('Y-m-d H:i:s');

Outputs:

2017-10-01 20:43:22
2017-10-01 20:43:23
2017-10-01 20:43:24