From: Gaƫl Bouchez Date: Wed, 16 Jul 2014 07:29:47 +0000 (+0200) Subject: Fixed the date filter's timezone not being set correctly with strings X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=44aaa5b2286cda5d8737fb8e467a953b7938d227;p=konrad%2Ftwig.git Fixed the date filter's timezone not being set correctly with strings --- 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;