little-sumo-labs / time-ago-twig-filter
Extensions for Twig, giving a date in a more understandable format
1.0.0
2018-04-04 20:39 UTC
Requires
- php: >= 7.1.0
- twig/twig: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.11
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^3.2
This package is not auto-updated.
Last update: 2024-11-15 08:32:44 UTC
README
Extensions for Twig, giving a date in a more understandable format (e.g. '1 hour ago', 'yesterday', 'tomorrow', 'in 2 weeks')
Installation
composer require little-sumo-labs/time-ago-twig-filter
How to Use it
Import the filter namespace
use littlesumolabs\timeago\relativeTimerFilter as relativeTimer;
initializing the filter for Twig
$twig->addExtension(new relativeTimer());
Or
$twig->addExtension(new relativeTimer('America/Chicago'));
Creation of 'date' variable, which is injected into the Twig view
echo $twig->render('index.twig', [ 'date' => date("d M Y H:i:s"), 'timer' => date('d M Y H:i:s', strtotime('-1 hour', strtotime('now'))), 'timer2' => date("d M Y H:i:s", strtotime('+1 day', strtotime('now'))) ]);
Using the filter in the Twig view
{{ date|relativetimer }} <br /> {{ timer|relativetimer }} <br /> {{ timer2|relativetimer }}
Example of use
future developments
- Adding translations for different languages (French, English, Spanish, etc ...)
- ...
Useful links
Articles divers
- Timer relatif
- Créer une date relative en PHP
- Formats supportés de temps et de dates
- Liste des Fuseaux Horaires Supportés en PHP