forked from twigphp/Twig
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged branch Seldaek/date_modify (PR twigphp#757)
Commits ------- ae85586 Add docs for date_modify 0366cf6 Fix docs of date filter Discussion ---------- Date modify filter This is probably possible via `date(foo)|modify('-1day')|format()`, but it's non obvious and a dedicated filter might be a bit more prominent. --------------------------------------------------------------------------- by fabpot at 2012-06-22T07:01:32Z Just a quick thought: As it modifies the date, it should probably be a function, not a filter. --------------------------------------------------------------------------- by stof at 2012-06-22T07:24:52Z @fabpot Aren't filters meant to transform the value ?
- Loading branch information
Showing
4 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
``date_modify`` | ||
=============== | ||
|
||
.. versionadded:: 1.9 | ||
The date_modify filter has been added in Twig 1.9. | ||
|
||
The ``date_modify`` filter modifies a date with a given modifier string: | ||
|
||
.. code-block:: jinja | ||
{{ post.published_at|date_modify("+1 day")|date("m/d/Y") }} | ||
The ``date_modify`` filter accepts strings (it must be in a format supported by the | ||
`strtotime`_ function) or `DateTime`_ instances. You can easily combine it with the `date`_ | ||
filter for formatting. | ||
|
||
.. _`strtotime`: http://www.php.net/strtotime | ||
.. _`DateTime`: http://www.php.net/DateTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
"date_modify" filter | ||
--TEMPLATE-- | ||
{{ date1|date_modify('-1day')|date('Y-m-d H:i:s') }} | ||
{{ date2|date_modify('-1day')|date('Y-m-d H:i:s') }} | ||
--DATA-- | ||
date_default_timezone_set('UTC'); | ||
return array( | ||
'date1' => '2010-10-04 13:45', | ||
'date2' => new DateTime('2010-10-04 13:45'), | ||
) | ||
--EXPECT-- | ||
2010-10-03 13:45:00 | ||
2010-10-03 13:45:00 |