From: Fabien Potencier Date: Wed, 15 Feb 2012 16:21:29 +0000 (+0100) Subject: merged branch mlehner/default_timezone (PR #635) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=7d30dc6f04f48264db8a82b0341a8460735e8b5b;p=web%2Fkonrad%2Ftwig.git merged branch mlehner/default_timezone (PR #635) Commits ------- 5699753 added setTimezone to allow globally overriding the timezone when formating dates Discussion ---------- Allow setting global timezone for date formatting My API returns dates in a string format of 2012-02-14T00:35:37+00:00. When parsed by the DateTime constructor, the timezone for that new object is UTC. Without specifying every time I use the date filter there was no way to globally influence the timezone used. I added setTimezone() to the core extension that functions similar to setDateFormat() except that there is no timezone set by default to allow for backwards compatibility. --- 7d30dc6f04f48264db8a82b0341a8460735e8b5b diff --cc lib/Twig/Extension/Core.php index 6225557,ae25758..cfbdbdc --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@@ -401,8 -367,12 +426,12 @@@ function twig_date_converter($date = nu $date->setTimezone($timezone); } + else if (($timezone = $env->getExtension('core')->getTimezone()) instanceof DateTimeZone) + { + $date->setTimezone($timezone); + } - return $date->format($format); + return $date; } /**