Skip to content

Commit 144c4da

Browse files
committed
Fix timezone fallback to CoreExtension in IntlExtension
This is probably a regression from twigphp#3844
1 parent 9f42a76 commit 144c4da

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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)