Clocks
use Derafu\Date\Service\FixedClock;
use Derafu\Date\Service\SystemClock;
Nothing in the package reads the current time by itself. What depends on “now” (Month::current(), the age, the days until today, formatElapsed()) takes a Psr\Clock\ClockInterface, and uses SystemClock if it is not given one.
| Class | What it gives |
|---|---|
SystemClock |
The current moment. |
FixedClock |
Always the same moment, given as a date or as a text. |
$clock = new FixedClock('2024-01-15 12:00:00');
Month::current($clock); // 2024-01
DateCalculator::age('2004-01-16', $clock); // 19
(new DateFormatter($clock))->formatElapsed('2024-01-15 11:45:00'); // 15 minutes ago
A FixedClock is for tests and for calculations that must be made as of a date. Any other PSR-20 clock works in their place.
On this page
Last updated on 05/11/2026
by Anonymous