cakephp/chronos
Chronos is an immutable date and datetime library for PHP. It offers Chronos and ChronosDate objects that prevent accidental modification, keeping data predictable, and adds handy conveniences beyond native DateTime. Install via Composer with cakephp/chronos.
Chronos (an instant with timezone), ChronosDate (calendar date, time frozen at 00:00:00), and ChronosTime (wall-clock time, no date). That distinction is a product decision, not a technical one: a birthday, a delivery window, and a billing timestamp fail in different ways and should not share a type. This package makes the correct model the path of least resistance.addElapsedHours/Minutes/Seconds (true inverses of diffIn*) gives us a defensible answer to "is an hour always an hour?" without hand-rolled timestamp math.setTestNow() and the newer scoped withTestNow() let us specify and demo time-dependent behavior deterministically ("what does the customer see on day 30?"). This is a product-quality lever: it reduces flaky tests that block releases and makes edge-case acceptance criteria actually verifiable before launch.ClockFactory implements PSR-20, so "what time is it?" becomes an injected dependency. Adopting it early is cheap; retrofitting it into a mature codebase after a timezone incident is not.nextOccurrenceOf, previousOccurrenceOf, startOfHour/endOfHour), and scoped time mocking map directly onto calendar/booking/scheduling roadmap items. It reduces bespoke date utility code we would otherwise own and maintain.Good fit when:
DateTime objects around by reference.Look elsewhere or defer when:
DateTimeInterface. In 3.x, Chronos no longer extends DateTimeImmutable or implements DateTimeInterface, and ChronosDate deliberately does not share types with Chronos. ORMs, serializers, API schema generators, and third-party SDKs that demand native datetime types will need adapters. Spike that interop surface before committing.To executives: This is a small, MIT-licensed, actively maintained date/time library with no license cost, no vendor lock-in, and no infrastructure footprint — one Composer dependency. The business case is defect prevention, not features: it structurally removes a recurring class of production bugs where dates shift by a day, timestamps mutate unexpectedly, or elapsed-time calculations go wrong across daylight-saving transitions. Those bugs are expensive precisely because they are rare, hard to reproduce, and often surface in billing, scheduling, or compliance reporting. The one honest caution is that it is not a drop-in replacement for PHP's native datetime interface, so we would wrap it behind our own interfaces — which is the right architecture regardless of which library we pick.
To engineering: Immutable by default, so modification bugs disappear. Three explicit types eliminate the date-vs-instant conflation that causes "birthday renders a day early" and "midnight UTC rolls back a date." A first-class test clock with scoped mocking removes the flaky, sleep-based tests that block CI. PSR-20 ClockFactory gives a clean injection seam. DST-safe elapsed arithmetic is provided as the true inverse of the diff methods, so we stop hand-rolling Unix-timestamp math. Costs are real and bounded: we do not get DateTimeInterface in 3.x, so we write adapters at ORM and serialization boundaries, we pin PHP versions per the version map, and we follow the documented 2.x→3.x deprecation path rather than jumping majors.
Proposed ask: approve a timeboxed pilot — one bounded, date-heavy area (scheduling or billing period logic), one to two sprints, with explicit success criteria: reduction in date-related defects, reduction in time-dependent test flakiness, and lines of bespoke date utility code deleted. Adopt as the standard for new domain code only; no retrofit mandate until the pilot reports.
How can I help you explore Laravel packages today?