From 9b95570829e19412f9bacd87632222acb1532316 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 5 Jan 2014 00:37:22 +0100 Subject: [PATCH] fixed the conversion of the special '0000-00-00 00:00' date --- CHANGELOG | 1 + lib/Twig/Extension/Core.php | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) 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; -- 1.7.2.5