🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
DatePoint — application-clock moment
Purpose
A DateTimeImmutable subclass: new DatePoint() takes “now” from the global clock (ClockHolder); parse errors are typed exceptions instead of false with a warning.
What for and how to use
A drop-in replacement for new DateTimeImmutable() in testable code: moments automatically follow the substituted clock.
Example
ClockHolder::set(MockClock::from('2026-01-01 00:00:00', 'UTC'));
$point = new DatePoint(); // 2026-01-01 from the mock clock
$later = new DatePoint('+1 hour');
DatePoint::createFromFormat('Y-m-d', 'garbage'); // typed exception
Anti-patterns
With DI prefer an explicit ClockInterface; DatePoint is a bridge for injection-free code.
Lifecycle
flowchart LR
A[ClockHolder] -->|now| B[new DatePoint]
B --> C[DateTimeImmutable API]
B -->|modify/createFromFormat errors| D[/InvalidClockValueException/]
Feature comparison with competitors
| Aspect | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Moment from the global clock | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Typed parse errors | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
Full DateTimeImmutable API | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Zero implementation dependencies | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Total | 🏆 4 | 3 | 3 | 0 | 0 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano