Skip to content

Commit

Permalink
alphp#15 Fix fatal error with non-Gregorian locales
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Dec 18, 2023
1 parent 51a4ef7 commit a959850
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/php-8.1-strftime.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) :
// in formatted strings.
// To adjust for this, a custom calendar can be supplied with a cutover date arbitrarily far in the past.
$calendar = IntlGregorianCalendar::createInstance();
$calendar->setGregorianChange(PHP_INT_MIN);
// NOTE: IntlGregorianCalendar::createInstance DOES NOT return an IntlGregorianCalendar instance when
// using a non-Gregorian locale (e.g. fa_IR)! In that case, setGregorianChange will not exist.
if (method_exists($calendar, 'setGregorianChange')) $calendar->setGregorianChange(PHP_INT_MIN);

return (new IntlDateFormatter($locale, $date_type, $time_type, $tz, $calendar, $pattern))->format($timestamp);
};
Expand Down

0 comments on commit a959850

Please sign in to comment.