🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
DatePoint — Zeitpunkt von der Anwendungsuhr
Zweck
Eine Unterklasse von DateTimeImmutable: new DatePoint() bezieht das „Jetzt" von der globalen Uhr (ClockHolder); Parse-Fehler sind typisierte Ausnahmen statt false mit einer Warnung.
Wofür und wie einzusetzen
Ein Drop-in-Ersatz für new DateTimeImmutable() in testbarem Code: Zeitpunkte folgen automatisch der ersetzten Uhr.
Beispiel
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-Muster
Bei DI ist ein explizites ClockInterface vorzuziehen; DatePoint ist eine Brücke für Code ohne Injektion.
Lebenszyklus
flowchart LR
A[ClockHolder] -->|now| B[new DatePoint]
B --> C[DateTimeImmutable API]
B -->|modify/createFromFormat errors| D[/InvalidClockValueException/]
Funktionsvergleich mit Alternativen
| Aspekt | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Zeitpunkt von der globalen Uhr | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Typisierte Parse-Fehler | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
Vollständige DateTimeImmutable-API | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Null Implementierungsabhängigkeiten | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Gesamt | 🏆 4 | 3 | 3 | 0 | 0 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano