🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
TruncatingClock — truncating clock
Purpose
Decorator: floors readings to a unit boundary (TruncationUnit: second, minute, hour, day...).
What for and how to use
Per-minute cache keys, metric bucketing: TruncatingClock::toMinute($clock) — parity with beste MinuteClock, but for any unit.
Example
$byMinute = TruncatingClock::toMinute(SystemClock::utc());
$byHour = new TruncatingClock(SystemClock::utc(), TruncationUnit::Hour);
$key = 'stats:' . $byHour->now()->format('YmdH');
Anti-patterns
Not for precise event stamps — microseconds are deliberately dropped.
Lifecycle
flowchart LR
A[Inner clock] -->|12:34:56.789| B[TruncatingClock unit=Minute]
B -->|12:34:00.000| C[Consumer]
Feature comparison with competitors
| Aspect | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Arbitrary truncation unit | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Truncation to a minute | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Decorator over any clock | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Cheap timestamp() without an object | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Total | 🏆 4 | 0 | 0 | 0 | 2 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano