mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-29 19:47:06 +00:00
Fix timezone fallback to CoreExtension in IntlExtension
This is probably a regression from #3844
This commit is contained in:
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user