Files
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

42 lines
1.2 KiB
ReStructuredText

The Date Extension
===================
The *Date* extension provides the ``time_diff`` filter.
You need to register this extension before using the ``time_diff`` filter::
$twig->addExtension(new Twig_Extensions_Extension_Date());
``time_diff``
-------------
Use the ``time_diff`` filter to render the difference between a date and now.
.. code-block:: jinja
{{ post.published_at|time_diff }}
The example above will output a string like ``4 seconds ago`` or ``in 1 month``,
depending on the filtered date.
.. note::
Internally, Twig uses the PHP ``DateTime::diff()`` method for calculating the
difference between dates, this means that PHP 5.3+ is required.
Arguments
~~~~~~~~~
* ``date``: The date for calculate the difference from now. Can be a string
or a DateTime instance.
* ``now``: The date that should be used as now. Can be a string or
a DateTime instance. Do not set this argument to use current date.
Translation
~~~~~~~~~~~
To get a translatable output, give a ``Symfony\Component\Translation\TranslatorInterface``
as constructor argument. The returned string is formatted as ``diff.ago.XXX``
or ``diff.in.XXX`` where ``XXX`` can be any valid unit: second, minute, hour, day, month, year.