---
title: "Clocks"
description: "SystemClock and FixedClock, the PSR-20 clocks of the package"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-11-05"
last_update: "2026-11-05"
time_minutes: 1
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/core/date/clocks"
---

# Clocks

```php
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. |

```php
$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.



---
Last updated on 05/11/2026

