diff --git a/src/php-8.1-strftime.php b/src/php-8.1-strftime.php index 4f8f916..076538e 100644 --- a/src/php-8.1-strftime.php +++ b/src/php-8.1-strftime.php @@ -8,6 +8,7 @@ use IntlDateFormatter; use IntlGregorianCalendar; use InvalidArgumentException; + use Locale; /** * Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible) @@ -40,12 +41,7 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) : $timestamp->setTimezone(new DateTimeZone(date_default_timezone_get())); - if (empty($locale)) { - // get current locale - $locale = setlocale(LC_TIME, '0'); - } - // remove trailing part not supported by ext-intl locale - $locale = preg_replace('/[^\w-].*$/', '', $locale); + $locale = Locale::canonicalize($locale ?? setlocale(LC_TIME, '0')); $intl_formats = [ '%a' => 'EEE', // An abbreviated textual representation of the day Sun through Sat