🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
OffsetClock — offset clock
Purpose
Decorator: “time travel” relative to the inner clock by a fixed offset (seconds or DateInterval, any sign).
What for and how to use
Staging “in the future” (promo/deadline testing), compensating skew with an external system: OffsetClock::aheadBy($clock, 3600.0).
Example
$tomorrow = OffsetClock::aheadBy(SystemClock::utc(), 86_400.0);
$yesterday = OffsetClock::behindBy(SystemClock::utc(), new DateInterval('P1D'));
Anti-patterns
Not for test determinism — time still flows inside; use FrozenClock/MockClock in tests.
Lifecycle
flowchart LR
A[Inner clock] -->|now()| B[OffsetClock]
B -->|+offset| C[Shifted moment]
C --> D[Consumer]
Feature comparison with competitors
| Aspect | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Offset as a decorator without global state | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Interval or seconds, any sign | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Output timezone override | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Composes with any package clock | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Total | 🏆 4 | 0 | 0 | 0 | 0 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano