siniliote-twig / date-extra
A Twig extension to transform time diff in human readable
Installs: 1 689
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1.3
- twig/twig: ^2.7|^3.0
Requires (Dev)
- symfony/phpunit-bridge: ^4.4.9|^5.0.9|^6.0
- symfony/translation-contracts: ^1.1|^2|^3
Suggests
- symfony/translation: Allow the time_diff output to be translated
This package is not auto-updated.
Last update: 2024-12-12 08:59:55 UTC
README
The Date extension provides the time_diff
filter.
time_diff
Use the time_diff
filter to render the difference between a date and now.
{{ 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.
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\Contracts\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.