CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

FAQ

How is the package different from symfony/clock? It is a superset: besides system/mock/monotonic clocks it adds offset, scale and truncation decorators, step and queue clocks, TimeSpan, Deadline, Stopwatch, cheap timestamp()/microtime(). Plus CalendarDate — Carbon-grade calendar with localisation. Lightweight dependencies: psr/clock and cloud-castle/inflector (no polyfills or ICU).

Does it replace Carbon? Yes, for most scenarios. CalendarDate provides a Carbon-parity calendar API: month/year arithmetic with overflow control (addMonthsNoOverflow()), predicates, diffs, navigation, formatters, deterministic parsing of relative strings and diffForHumans() in 6 languages without ICU/ext-intl. The only gap is tight Laravel integration (facades, Eloquent date casts).

Why does TimeSpan reject months? The absolute duration of a month is undefined (28–31 days), so TimeSpan is an exact nanosecond duration. For calendar month/year arithmetic use CalendarDate (addMonthsNoOverflow(), addYears()).

Is ClockHolder thread-safe? As any PHP static state — within a single process. In swoole/parallel environments inject ClockInterface explicitly.

How expensive is now()? On par with the best competitors (see Comparison); timestamp() is significantly cheaper than now()->getTimestamp() on any clock.


🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano