Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extra/intl-extra/IntlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'm
$date = twig_date_converter($env, $date, $timezone);

$formatterTimezone = $timezone;
if (false === $formatterTimezone) {
if (null === $formatterTimezone) {
$formatterTimezone = $date->getTimezone();
} elseif (\is_string($formatterTimezone)) {
$formatterTimezone = new \DateTimeZone($timezone);
Expand Down
15 changes: 15 additions & 0 deletions extra/intl-extra/Tests/IntlExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Twig\Environment;
use Twig\Extension\CoreExtension;
use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\ArrayLoader;

Expand All @@ -30,6 +31,20 @@ public function testFormatterWithoutProto()
);
}

public function testFormatterWithoutProtoFallsBackToCoreExtensionTimezone()
{
$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->assertSame(
'Feb 20, 2020, 3:37:00 PM',
$ext->formatDateTime($env, new \DateTime('2020-02-20T13:37:00+00:00', new \DateTimeZone('UTC')))
);
}

public function testFormatterProto()
{
$dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris'));
Expand Down