-
Couldn't load subscription status.
- Fork 8k
Description
Description
Date arithmetic in timelib (and so in DateTimeImmutable) is based on the "proleptic gregorian" calendar (i.e. a calendar that does not have a cutover switching to the Julian calendar for dates before the cutover).
On the other hand, IntlDateFormatter::GREGORIAN (the default calendar in IntlDateFormatter) is an hybrid calendar switching to Julian calendar for past dates.
There is a way to use a proleptic Gregorian calendar by providing a calendar object explicitly:
$calendar = new \IntlGregorianCalendar();
$calendar->setGregorianChange(-INF);However, this is a lot less convenient than using of the integer constants (the timezone passed to the formatter is ignored, having to set it in the calendar object instead, for instance).
The mismatch between the behavior of DateTimeImmutable and IntlDateFormatter leads to surprising issues (which happen only when using dates far in the past, making them easy to miss). See symfony/symfony#31057 for an issue opened in Symfony which is caused by that mismatch.
It would be great to expose a predefined constant allowing to easily use the proleptic gregorian calendar in IntlDateFormatter (maybe even making it the default in the future, but that may be tricky to provide a migration path).