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

This package is not auto-updated.

Last update: 2024-11-15 08:32:44 UTC


README

Build Status Coverage Status

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

page d'exemple

future developments

  • Adding translations for different languages (French, English, Spanish, etc ...)
  • ...

Useful links

Articles divers

Documentation Twig