🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
CalendarDate — Kalenderarithmetik auf Carbon-Niveau
Zweck
Ein Kalenderdatum auf Basis von DateTimeImmutable: Monats-/Jahresarithmetik mit Überlaufkontrolle (addMonthsNoOverflow), Periodengrenzen, isoFormat und diffForHumans in 6 Sprachen — ohne ICU/ext-intl. Die Deklinationen liefert cloud-castle/inflector.
Wofür und wie einzusetzen
Ein Carbon-Ersatz dort, wo nur korrekte Kalenderarithmetik und lokalisierte Ausgabe benötigt werden: CalendarDate::parse()/now(), dann addMonthsNoOverflow(), startOfQuarter(), diffForHumans(null, 'ru').
Beispiel
$date = CalendarDate::parse('2026-01-31', 'UTC');
$date->addMonthsNoOverflow(1)->format('Y-m-d'); // 2026-02-28, not “3 March”
$date->isWeekend(); // is it a weekend day
$date->diffInDays($other); // integer difference
$date->next(5)->format('Y-m-d'); // the nearest Friday
$date->subDays(5)->diffForHumans($date, 'en'); // “5 days ago”
Anti-Muster
Wähle es nicht allein wegen der engen Laravel-Integration (Fassaden, Eloquent-Datums-Casts) — das ist der einzige Bereich, in dem Carbon reichhaltiger ist; die Kalender-API selbst ist auf Carbon-Paritätsniveau.
Lebenszyklus
flowchart LR
A[parse / now / fromClock] --> B[CalendarDate]
B -->|addMonthsNoOverflow / startOfQuarter| B
B -->|isWeekend / diffInDays / next| B
B -->|isoFormat / diffForHumans| C[CloudCastle inflector]
C --> D[Localised string]
Funktionsvergleich mit Alternativen
| Aspekt | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Monatsarithmetik ohne Überlauf | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Periodengrenzen (startOf/endOf) | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Wochentags- und relative Prädikate (isWeekend/isToday) | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Ganzzahlige Differenzen (diffInDays…diffInYears) | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Navigation (next/previous/firstOfMonth) | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| diffForHumans in 6 Sprachen | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Lokalisierung ohne ICU/ext-intl | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Datum von der injizierten Uhr (Determinismus) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Gesamt | 🏆 8 | 0 | 6 | 0 | 0 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano