diff options
Diffstat (limited to 'vendor/twig/twig/doc/filters/date.rst')
-rw-r--r-- | vendor/twig/twig/doc/filters/date.rst | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/twig/twig/doc/filters/date.rst b/vendor/twig/twig/doc/filters/date.rst new file mode 100644 index 00000000..8e2f31fa --- /dev/null +++ b/vendor/twig/twig/doc/filters/date.rst | |||
@@ -0,0 +1,88 @@ | |||
1 | ``date`` | ||
2 | ======== | ||
3 | |||
4 | .. versionadded:: 1.1 | ||
5 | The timezone support has been added in Twig 1.1. | ||
6 | |||
7 | .. versionadded:: 1.5 | ||
8 | The default date format support has been added in Twig 1.5. | ||
9 | |||
10 | .. versionadded:: 1.6.1 | ||
11 | The default timezone support has been added in Twig 1.6.1. | ||
12 | |||
13 | .. versionadded:: 1.11.0 | ||
14 | The introduction of the false value for the timezone was introduced in Twig 1.11.0 | ||
15 | |||
16 | The ``date`` filter formats a date to a given format: | ||
17 | |||
18 | .. code-block:: jinja | ||
19 | |||
20 | {{ post.published_at|date("m/d/Y") }} | ||
21 | |||
22 | The ``date`` filter accepts strings (it must be in a format supported by the | ||
23 | `strtotime`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For | ||
24 | instance, to display the current date, filter the word "now": | ||
25 | |||
26 | .. code-block:: jinja | ||
27 | |||
28 | {{ "now"|date("m/d/Y") }} | ||
29 | |||
30 | To escape words and characters in the date format use ``\\`` in front of each | ||
31 | character: | ||
32 | |||
33 | .. code-block:: jinja | ||
34 | |||
35 | {{ post.published_at|date("F jS \\a\\t g:ia") }} | ||
36 | |||
37 | If the value passed to the ``date`` filter is ``null``, it will return the | ||
38 | current date by default. If an empty string is desired instead of the current | ||
39 | date, use a ternary operator: | ||
40 | |||
41 | .. code-block:: jinja | ||
42 | |||
43 | {{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }} | ||
44 | |||
45 | If no format is provided, Twig will use the default one: ``F j, Y H:i``. This | ||
46 | default can be easily changed by calling the ``setDateFormat()`` method on the | ||
47 | ``core`` extension instance. The first argument is the default format for | ||
48 | dates and the second one is the default format for date intervals: | ||
49 | |||
50 | .. code-block:: php | ||
51 | |||
52 | $twig = new Twig_Environment($loader); | ||
53 | $twig->getExtension('core')->setDateFormat('d/m/Y', '%d days'); | ||
54 | |||
55 | Timezone | ||
56 | -------- | ||
57 | |||
58 | By default, the date is displayed by applying the default timezone (the one | ||
59 | specified in php.ini or declared in Twig -- see below), but you can override | ||
60 | it by explicitly specifying a timezone: | ||
61 | |||
62 | .. code-block:: jinja | ||
63 | |||
64 | {{ post.published_at|date("m/d/Y", "Europe/Paris") }} | ||
65 | |||
66 | If the date is already a DateTime object, and if you want to keep its current | ||
67 | timezone, pass ``false`` as the timezone value: | ||
68 | |||
69 | .. code-block:: jinja | ||
70 | |||
71 | {{ post.published_at|date("m/d/Y", false) }} | ||
72 | |||
73 | The default timezone can also be set globally by calling ``setTimezone()``: | ||
74 | |||
75 | .. code-block:: php | ||
76 | |||
77 | $twig = new Twig_Environment($loader); | ||
78 | $twig->getExtension('core')->setTimezone('Europe/Paris'); | ||
79 | |||
80 | Arguments | ||
81 | --------- | ||
82 | |||
83 | * ``format``: The date format | ||
84 | * ``timezone``: The date timezone | ||
85 | |||
86 | .. _`strtotime`: http://www.php.net/strtotime | ||
87 | .. _`DateTime`: http://www.php.net/DateTime | ||
88 | .. _`DateInterval`: http://www.php.net/DateInterval | ||