Skip to content

Releases: phpnomad/chronos-integration

1.0.0

27 May 20:22

Choose a tag to compare

Initial release. Chronos-backed implementation of the phpnomad/chrono catalog. The default comprehensive integration: roughly a fifth the install footprint of nesbot/carbon with effectively the same surface, using ext-intl for locale-aware formatting instead of bundled translation files.

What's in the box

ChronosChronoStrategy — a single concrete that implements 28 chrono interfaces against cakephp/chronos, with IntlDateFormatter providing the locale-aware formatting Chronos 3.x dropped.

Clock

  • ClockStrategy

Predicates

  • CanCheckIfPast, CanCheckIfFuture, CanCheckIfWeekend, CanCheckIfWeekday
  • CanCheckSameDay, CanCheckSameMonth, CanCheckSameYear, CanCheckBetween

Arithmetic

  • CanApplyModifier, CanAddInterval, CanSubtractInterval

Calendar boundaries

  • CanGetStartOfDay, CanGetEndOfDay, CanGetStartOfMonth, CanGetEndOfMonth, CanGetStartOfYear, CanGetEndOfYear

Difference

  • CanGetDifference, CanGetDifferenceInDays, CanGetDifferenceInHours, CanGetDifferenceInMinutes, CanGetDifferenceInSeconds

Parsing and formatting

  • CanParseDate, CanParseDateWithFormat
  • CanFormatDate, CanFormatLocalizedDate, CanFormatRelativeTime

Configuration

The strategy takes HasTimezone and HasLocale constructor dependencies — both resolved by the DI container from whichever paired integration provides them. Pair with phpnomad/wordpress-integration 4.1.0+ for WordPress-backed timezone and locale, or supply your own concretes.

public function __construct(
    HasTimezone \$timezone,
    HasLocale   \$locale,
)

Behavior notes

  • Format syntax differs across methods. format() takes PHP's native date() syntax. formatLocalized() takes ICU pattern syntax via IntlDateFormatter — see the ICU patterns reference for the grammar.
  • relative() is English-only. Chronos 3.x ships a deliberately English-only diffForHumans translator. The injected locale is ignored by this method (documented in the strategy and tested). Apps needing locale-aware relative-time strings should pair with phpnomad/wordpress-integration or phpnomad/carbon-integration.
  • isBetween is inclusive on both bounds.
  • apply() uses native DateTimeImmutable::modify(); PHP's default month-overflow behavior applies.
  • parseFormat() throws InvalidArgumentException on unparseable input.
  • diffIn* methods are signed.
  • Chronos's setTestNow() is honored by now() and therefore by every predicate.

Requirements

PHP 8.2 or newer. ext-intl. phpnomad/chrono ^1.0, cakephp/chronos ^2.4 || ^3.0.

Tests

39 tests, 77 assertions covering interface membership, the deliberate non-implementation of HasTimezone/HasLocale, clock and timezone resolution via injected providers, every predicate, arithmetic, calendar boundaries, signed diff methods, flexible and strict parsing, native and ICU-locale-aware formatting, and the documented English-only behavior of relative(). Two locale-aware format tests skip gracefully when ext-intl is unavailable.