From 44aaa5b2286cda5d8737fb8e467a953b7938d227 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ga=C3=ABl=20Bouchez?= Date: Wed, 16 Jul 2014 09:29:47 +0200 Subject: [PATCH] Fixed the date filter's timezone not being set correctly with strings --- lib/Twig/Extension/Core.php | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 750ef0f..031ef24 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -496,23 +496,23 @@ function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) { // determine the timezone - if (!$timezone) { - $defaultTimezone = $env->getExtension('core')->getTimezone(); - } elseif (!$timezone instanceof DateTimeZone) { - $defaultTimezone = new DateTimeZone($timezone); - } else { - $defaultTimezone = $timezone; + if (false !== $timezone) { + if (null === $timezone) { + $timezone = $env->getExtension('core')->getTimezone(); + } elseif (!$timezone instanceof DateTimeZone) { + $timezone = new DateTimeZone($timezone); + } } // immutable dates if ($date instanceof DateTimeImmutable) { - return false !== $timezone ? $date->setTimezone($defaultTimezone) : $date; + return false !== $timezone ? $date->setTimezone($timezone) : $date; } if ($date instanceof DateTime || $date instanceof DateTimeInterface) { $date = clone $date; if (false !== $timezone) { - $date->setTimezone($defaultTimezone); + $date->setTimezone($timezone); } return $date; @@ -523,9 +523,9 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu $date = '@'.$date; } - $date = new DateTime($date, $defaultTimezone); + $date = new DateTime($date, $env->getExtension('core')->getTimezone()); if (false !== $timezone) { - $date->setTimezone($defaultTimezone); + $date->setTimezone($timezone); } return $date; -- 1.7.2.5