From 89781f6d97981397c8c8a13ca679919f39628c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alfaiate?= Date: Mon, 1 Apr 2024 14:39:28 +0700 Subject: [PATCH] Fix exception when timezone is false --- IntlExtension.php | 2 +- Tests/IntlExtensionTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/IntlExtension.php b/IntlExtension.php index 0b33331..d932e7f 100644 --- a/IntlExtension.php +++ b/IntlExtension.php @@ -372,7 +372,7 @@ public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'm $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); diff --git a/Tests/IntlExtensionTest.php b/Tests/IntlExtensionTest.php index 688a415..91aa9e8 100644 --- a/Tests/IntlExtensionTest.php +++ b/Tests/IntlExtensionTest.php @@ -45,6 +45,20 @@ public function testFormatterWithoutProtoFallsBackToCoreExtensionTimezone() ); } + 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'));