* 1.7.0-DEV
+ * added a way to set the default global timezone for dates
* fixed the slice filter on strings when the length is not specified
* fixed the creation of the cache directory in case of a race condition
.. versionadded:: 1.5
The default date format support has been added in Twig 1.5.
+.. versionadded:: 1.7
+ The default timezone support has been added in Twig 1.7.
+
The ``date`` filter formats a date to a given format:
.. code-block:: jinja
{{ 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 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:
+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', '%d days');
+The default timezone can also be set globally by calling ``setTimezone()``:
+
+.. code-block:: php
+
+ $twig = new Twig_Environment($loader);
+ $twig->getExtension('core')->setTimezone('Europe/Paris');
+
.. _`date`: http://www.php.net/date
.. _`DateTime`: http://www.php.net/DateTime
.. _`DateInterval`: http://www.php.net/DateInterval
.. versionadded:: 1.6
The date function has been added in Twig 1.6.
+.. versionadded:: 1.7
+ The default timezone support has been added in Twig 1.7.
+
Converts an argument to a date to allow date comparison:
.. code-block:: jinja
{# always! #}
{% endif %}
+.. note::
+
+ You can set the default timezone globally by calling ``setTimezone()`` on
+ the ``core`` extension instance:
+
+ .. code-block:: php
+
+ $twig = new Twig_Environment($loader);
+ $twig->getExtension('core')->setTimezone('Europe/Paris');
+
.. _`date`: http://www.php.net/date