From 8a5f6bf63b2c49dd1ca48c6f6e01b374e66ee16c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 24 Jun 2011 10:41:55 +0200 Subject: [PATCH] added doc and fixed CS for previous merge --- doc/templates.rst | 7 +++++++ lib/Twig/Extension/Core.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/templates.rst b/doc/templates.rst index 6dbc719..5f26722 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -1115,6 +1115,9 @@ List of built-in Filters ``date`` ~~~~~~~~ +.. versionadded:: 1.1 + The timezone support has been added in Twig 1.1. + The ``date`` filter is able to format a date to a given format: .. code-block:: jinja @@ -1135,6 +1138,10 @@ To escape words and characters in the date format use ``\\`` in front of each ch {{ post.published_at|date("F jS \\a\\t g:ia") }} +You can also specify a timezone: + + {{ post.published_at|date("m/d/Y", "Europe/Paris") }} + ``format`` ~~~~~~~~~~ diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index c5b2e1b..b65f732 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -201,7 +201,7 @@ class Twig_Extension_Core extends Twig_Extension } } -function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = NULL) +function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = null) { if (!$date instanceof DateTime) { if (ctype_digit((string) $date)) { @@ -212,7 +212,7 @@ function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = NULL } } - if ($timezone !== NULL) { + if (null !== $timezone) { if (!$timezone instanceof DateTimeZone) { $timezone = new DateTimeZone($timezone); } -- 1.7.2.5