Consume time from a Clock

Fund package maintenance!

1.2.1 2024-03-04 20:22 UTC

This package is auto-updated.

Last update: 2024-06-04 20:53:43 UTC


This is the EventSauce Clock component, which provides a straight forward way to consume time. Using a clock makes your code easier to test.


composer require eventsauce/clock


This package provides two implementations of the EventSauce\Clock\Clock interface.

In your production configuration, use the EventSauce\Clock\SystemClock implementation.


use EventSauce\Clock\SystemClock;

$clock = new SystemClock(new DateTimeZone('UTC') /* timezone optional */);

$dateTimeImmutable = $clock->now();
$timezone = $clock->timeZone();

In your test configuration, use the EventSauce\Clock\TestClock implementation.


use EventSauce\Clock\TestClock;

$testClock = new TestClock();
$dateTimeImmutable = $testClock->now();
$timezone = $testClock->timeZone();

// move the clock forward
$testClock->moveForward(DateInterval::createFromDateString('1 day'));

// Skip to system "now"

// Fixate the clock to a specific date and time
$testClock->fixate('1987-11-24 18:33:10');