Skip to content

Commit

Permalink
Fix fatal error when using the default PHP locale #17
Browse files Browse the repository at this point in the history
  • Loading branch information
alphp committed Jan 25, 2024
1 parent f5e1ece commit 4c13c94
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/php-8.1-strftime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use IntlDateFormatter;
use IntlGregorianCalendar;
use InvalidArgumentException;
use Locale;

/**
* Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c13c94

Please sign in to comment.