p0v1n0m / time-ago-bundle

Provides a simple twig filter for expressing time difference in words.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimeAgoBundle

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.

Install

Composer (Packagist):

composer require eschmar/time-ago-bundle dev-master

app/Appkernel.php:

new Eschmar\TimeAgoBundle\EschmarTimeAgoBundle(),

Usage

$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'

Translations available

  • Dutch
  • English
  • French
  • German
  • Hungarian
  • Italian
  • Polish
  • Portuguese (Brazil)
  • Russian
  • Slovenian
  • Spanish
  • Swedish
  • Turkish
  • Ukranian

License

MIT License

About

Provides a simple twig filter for expressing time difference in words.

License:MIT License


Languages

Language:PHP 100.0%