From f907eb4ac55134f680ae95171d4ec09ac052714a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 15 Feb 2012 17:24:22 +0100 Subject: [PATCH] fixed previous merge --- lib/Twig/Extension/Core.php | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index cfbdbdc..e0daffb 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -52,11 +52,7 @@ class Twig_Extension_Core extends Twig_Extension */ public function setTimezone($timezone) { - if ($timezone instanceof DateTimeZone) { - $this->timezone = $timezone; - } else { - $this->timezone = new DateTimeZone($timezone); - } + $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); } /** @@ -184,7 +180,7 @@ class Twig_Extension_Core extends Twig_Extension 'constant' => new Twig_Function_Function('constant'), 'cycle' => new Twig_Function_Function('twig_cycle'), 'random' => new Twig_Function_Function('twig_random', array('needs_environment' => true)), - 'date' => new Twig_Function_Function('twig_date_converter'), + 'date' => new Twig_Function_Function('twig_date_converter', array('needs_environment' => true)), ); } @@ -386,7 +382,7 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $ return $date->format($format); } - return twig_date_converter($date, $timezone)->format($format); + return twig_date_converter($env, $date, $timezone)->format($format); } /** @@ -398,12 +394,13 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $ * {% endif %} * * + * @param Twig_Environment $env A Twig_Environment instance * @param DateTime|string $date A date * @param DateTimeZone|string $timezone A timezone * * @return DateTime A DateTime instance */ -function twig_date_converter($date = null, $timezone = null) +function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) { if ($date instanceof DateTime) { return $date; @@ -425,9 +422,7 @@ function twig_date_converter($date = null, $timezone = null) } $date->setTimezone($timezone); - } - else if (($timezone = $env->getExtension('core')->getTimezone()) instanceof DateTimeZone) - { + } elseif (($timezone = $env->getExtension('core')->getTimezone()) instanceof DateTimeZone) { $date->setTimezone($timezone); } -- 1.7.2.5