Skip to content

Commit 78e1cdd

Browse files
committed
bug #3903 Fix timezone fallback to CoreExtension in IntlExtension (keulinho)
This PR was merged into the 3.x branch. Discussion ---------- Fix timezone fallback to CoreExtension in IntlExtension This is probably a regression from #3844 Refer to my comment on the original MR: #3844 (comment) Commits ------- 144c4da Fix timezone fallback to CoreExtension in IntlExtension
2 parents 2f73ee3 + 144c4da commit 78e1cdd

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

extra/intl-extra/IntlExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'm
371371
$date = twig_date_converter($env, $date, $timezone);
372372

373373
$formatterTimezone = $timezone;
374-
if (false === $formatterTimezone) {
374+
if (null === $formatterTimezone) {
375375
$formatterTimezone = $date->getTimezone();
376376
} elseif (\is_string($formatterTimezone)) {
377377
$formatterTimezone = new \DateTimeZone($timezone);

extra/intl-extra/Tests/IntlExtensionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Twig\Environment;
16+
use Twig\Extension\CoreExtension;
1617
use Twig\Extra\Intl\IntlExtension;
1718
use Twig\Loader\ArrayLoader;
1819

@@ -30,6 +31,20 @@ public function testFormatterWithoutProto()
3031
);
3132
}
3233

34+
public function testFormatterWithoutProtoFallsBackToCoreExtensionTimezone()
35+
{
36+
$ext = new IntlExtension();
37+
$env = new Environment(new ArrayLoader());
38+
// EET is always +2 without changes for daylight saving time
39+
// so it has a fixed difference to UTC
40+
$env->getExtension(CoreExtension::class)->setTimezone('EET');
41+
42+
$this->assertSame(
43+
'Feb 20, 2020, 3:37:00 PM',
44+
$ext->formatDateTime($env, new \DateTime('2020-02-20T13:37:00+00:00', new \DateTimeZone('UTC')))
45+
);
46+
}
47+
3348
public function testFormatterProto()
3449
{
3550
$dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris'));

0 commit comments

Comments
 (0)