Fix timezone fallback to CoreExtension in IntlExtension

This is probably a regression from #3844
This commit is contained in:
Jonas Elfering
2023-11-03 15:14:20 +01:00
parent 9f42a76306
commit 144c4dac7f
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -371,7 +371,7 @@ final class IntlExtension extends AbstractExtension
$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);
@@ -13,6 +13,7 @@ namespace Twig\Extra\Intl\Tests;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
use Twig\Extension\CoreExtension;
use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\ArrayLoader;
@@ -30,6 +31,20 @@ class IntlExtensionTest extends TestCase
);
}
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'));