Fix exception when timezone is false

This commit is contained in:
Sébastien Alfaiate
2024-04-01 14:39:28 +07:00
committed by Fabien Potencier
parent b46e93c725
commit 7e8f5eb1a5
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -372,7 +372,7 @@ final class IntlExtension extends AbstractExtension
$date = CoreExtension::dateConverter($env, $date, $timezone);
$formatterTimezone = $timezone;
if (null === $formatterTimezone) {
if (null === $formatterTimezone || false === $formatterTimezone) {
$formatterTimezone = $date->getTimezone();
} elseif (\is_string($formatterTimezone)) {
$formatterTimezone = new \DateTimeZone($timezone);
@@ -45,6 +45,20 @@ class IntlExtensionTest extends TestCase
);
}
public function testFormatterWithoutProtoSkipTimezoneConverter()
{
$ext = new IntlExtension();
$env = new Environment(new ArrayLoader());
// EET is always +2 without changes for daylight saving time
// so it has a fixed difference to UTC
$env->getExtension(CoreExtension::class)->setTimezone('EET');
$this->assertStringStartsWith(
'Feb 20, 2020, 1:37:00',
$ext->formatDateTime($env, new \DateTime('2020-02-20T13:37:00+00:00', new \DateTimeZone('UTC')), 'medium', 'medium', '', false)
);
}
public function testFormatterProto()
{
$dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris'));