Skip to content

Commit

Permalink
Use Locale::canonicalize only if intl is available
Browse files Browse the repository at this point in the history
When intl isn't available, we don't really care about the locale anyway,
since only english results are returned
  • Loading branch information
splitbrain committed Jan 26, 2024
1 parent b6376b3 commit 0fb385e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/php-8.1-strftime.php
Expand Up @@ -6,7 +6,6 @@
use DateTimeZone;
use Exception;
use InvalidArgumentException;
use Locale;

/**
* Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)
Expand Down Expand Up @@ -39,9 +38,8 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) :

$timestamp->setTimezone(new DateTimeZone(date_default_timezone_get()));

$locale = Locale::canonicalize($locale ?? setlocale(LC_TIME, '0'));

if (class_exists('\\IntlDateFormatter') && !isset($_SERVER['STRFTIME_NO_INTL'])) {
$locale = \Locale::canonicalize($locale ?? setlocale(LC_TIME, '0'));
$locale_formatter = new \PHP81_BC\strftime\IntlLocaleFormatter($locale);
} else {
$locale_formatter = new \PHP81_BC\strftime\DateLocaleFormatter($locale);
Expand Down

0 comments on commit 0fb385e

Please sign in to comment.