From b2952743d19d40091c0bf82ce539651f72ba0867 Mon Sep 17 00:00:00 2001 From: alefranz Date: Thu, 29 Dec 2011 19:46:53 +0100 Subject: [PATCH] fix Date Format filter: DateInterval does not provide setTimezone() --- lib/Twig/Extension/Core.php | 28 +++++++++++++++------------- 1 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 126ff97..f521523 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -313,22 +313,24 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $ $format = $env->getExtension('core')->getDateFormat(); } - if (!$date instanceof DateTime && !$date instanceof DateInterval) { - $asString = (string) $date; - if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { - $date = new DateTime('@'.$date); - $date->setTimezone(new DateTimeZone(date_default_timezone_get())); - } else { - $date = new DateTime($date); + if (!$date instanceof DateInterval) { + if (!$date instanceof DateTime) { + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { + $date = new DateTime('@'.$date); + $date->setTimezone(new DateTimeZone(date_default_timezone_get())); + } else { + $date = new DateTime($date); + } } - } - if (null !== $timezone) { - if (!$timezone instanceof DateTimeZone) { - $timezone = new DateTimeZone($timezone); - } + if (null !== $timezone) { + if (!$timezone instanceof DateTimeZone) { + $timezone = new DateTimeZone($timezone); + } - $date->setTimezone($timezone); + $date->setTimezone($timezone); + } } return $date->format($format); -- 1.7.2.5