Provides a simple twig filter for expressing time difference in words for Symfony. Uses a range of +-7 days, after that, the actual date is returned.
Composer (Packagist):
composer require eschmar/time-ago-bundle dev-master
app/Appkernel.php:
new Eschmar\TimeAgoBundle\EschmarTimeAgoBundle(),
$now = new \DateTime();
$foo = new \DateTime();
$foo->modify('-3 minutes');
$bar = new \DateTime();
$bar->modify('-3 months');
$foobar = new \DateTime();
$foobar->modify('+4 hours');
{{ now|ago }}
{# just now #}
{{ foo|ago('r') }}
{# 3 minutes ago #}
{{ bar|ago('r') }}
{# actual date in 'r' format #}
{{ foobar|ago }}
{# in 4 hours #}
Change default format in config.yml
:
eschmar_time_ago:
format: 'Y-m-d H:i:s'
- Belarusian
- Croatian
- Dutch
- English
- French
- German
- Hindi
- Hungarian
- Indonesian
- Italian
- Polish
- Portuguese (Brazil)
- Romanian
- Russian
- Slovenian
- Spanish
- Swedish
- Turkish
- Ukranian
- Vietnamese
MIT License