From f64d976182a8babe2cec4239f7bde8d629ef8db8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Dec 2011 09:21:01 +0100 Subject: [PATCH] updated doc for the date filter --- doc/filters/date.rst | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/filters/date.rst b/doc/filters/date.rst index 897645e..60e94e2 100644 --- a/doc/filters/date.rst +++ b/doc/filters/date.rst @@ -13,9 +13,9 @@ The ``date`` filter formats a date to a given format: {{ post.published_at|date("m/d/Y") }} -The ``date`` filter accepts any date format supported by `date`_ and -`DateTime`_ instances. For instance, to display the current date, filter the -word "now": +The ``date`` filter accepts strings (it must be in a format supported by the +`date`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For +instance, to display the current date, filter the word "now": .. code-block:: jinja @@ -34,12 +34,15 @@ You can also specify a timezone: {{ post.published_at|date("m/d/Y", "Europe/Paris") }} If no format is provided, Twig will use the default one: ``F j, Y H:i``. This -default can be easily changed: +default can be easily changed by calling the `setDateFormat()` method on the +`core` extension instance. The first argument is the default format for dates +and the second one is the default format for date intervals: .. code-block:: php $twig = new Twig_Environment($loader); - $twig->getExtension('core')->setDateFormat('d/m/Y'); + $twig->getExtension('core')->setDateFormat('d/m/Y', '%d days'); -.. _`date`: http://www.php.net/date -.. _`DateTime`: http://www.php.net/manual/en/datetime.construct.php +.. _`date`: http://www.php.net/date +.. _`DateTime`: http://www.php.net/DateTime +.. _`DateInterval`: http://www.php.net/DateInterval -- 1.7.2.5