From: Fabien Potencier Date: Sat, 4 Jan 2014 23:37:22 +0000 (+0100) Subject: fixed the conversion of the special '0000-00-00 00:00' date X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=9b95570829e19412f9bacd87632222acb1532316;p=web%2Fkonrad%2Ftwig.git fixed the conversion of the special '0000-00-00 00:00' date --- diff --git a/CHANGELOG b/CHANGELOG index 6d0a147..cbc8805 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.15.1 (2013-XX-XX) + * fixed the conversion of the special '0000-00-00 00:00' date * added an error message when trying to import an undefined block from a trait * 1.15.0 (2013-12-06) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 14f73d2..9b4974a 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -504,15 +504,18 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu $defaultTimezone = $timezone; } + // immutable dates + if ($date instanceof DateTimeImmutable) { + return false !== $timezone ? $date->setTimezone($defaultTimezone) : $date; + } + if ($date instanceof DateTime || $date instanceof DateTimeInterface) { - $returningDate = new DateTime($date->format('c')); + $date = clone $date; if (false !== $timezone) { - $returningDate->setTimezone($defaultTimezone); - } else { - $returningDate->setTimezone($date->getTimezone()); + $date->setTimezone($defaultTimezone); } - return $returningDate; + return $date; } $asString = (string) $date;