Merge branch 'MDL-84983-405' of https://github.com/paulholden/moodle into MOODLE_405_STABLE

This commit is contained in:
Huong Nguyen
2025-04-28 10:56:34 +07:00
2 changed files with 17 additions and 1 deletions
+11 -1
View File
@@ -819,7 +819,17 @@ class core_date {
$calendar = IntlGregorianCalendar::createInstance($intltz);
$calendar->setGregorianChange(PHP_INT_MIN);
return (new IntlDateFormatter($locale, $date_type, $time_type, $intltz, $calendar, $pattern))->format($timestamp);
// We need to account for invalid locales here in recent PHP versions, and ensure we catch errors and switch
// back to a default value where an invalid locale is provided.
try {
$formatter = new IntlDateFormatter($locale, $date_type, $time_type, $intltz, $calendar, $pattern);
$result = $formatter->format($timestamp);
} catch (Error $e) {
$formatter = new IntlDateFormatter(null, $date_type, $time_type, $intltz, $calendar, $pattern);
$result = $formatter->format($timestamp);
}
return $result;
};
// Same order as https://www.php.net/manual/en/function.strftime.php