Developed with love by KnpLabs Hire us for your project!
26

time-ago-bundle

by eschmar

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

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):
sh
composer require eschmar/time-ago-bundle ^v2.0.0 # Symfony ^5.0

or for older symfony versions:
sh
composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.x
composer require eschmar/time-ago-bundle ~v0.4.0 # Symfony ^2.8
composer require eschmar/time-ago-bundle ~v0.5.0 # Symfony ^3.4

app/Appkernel.php (Symfony <4):
php
new Eschmar\TimeAgoBundle\EschmarTimeAgoBundle(),

Usage

{{ date('now')|ago }}
{# just now #}

{{ date('now').modify('-3 minutes')|ago }}
{# 3 minutes ago #}

{{ date('now').modify('-3 months')|ago('r') }}
{# actual date in 'r' format #}

{{ date('now').modify('+4 hours')|ago('r') }}
{# in 4 hours #}

Change default format in config.yml:

eschmar_time_ago:
    format: 'Y-m-d H:i:s'

Translations available

  • Belarusian
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • French
  • Finnish
  • German
  • Hindi
  • Hungarian
  • Indonesian
  • Italian
  • Malay
  • Norwegian
  • Polish
  • Portuguese (Brazil)
  • Romanian
  • Russian
  • Slovenian
  • Spanish
  • Swedish
  • Tagalog
  • Turkish
  • Ukranian
  • Vietnamese

License

MIT License

MIT License

Copyright (c) 2016 Marcel Eschmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
  • Update readme for symfony 5.0
    By eschmar, 3 months ago
  • Migrate to new Translator::trans() interface
    By eschmar, 3 months ago
  • Switch to new di contract
    By eschmar, 3 months ago
  • Update to new naming scheme
    By eschmar, 3 months ago
  • Update to new twig namespaces
    By eschmar, 3 months ago
  • Merge pull request #43 from eschmar/feature/readme
    By web-flow, 10 months ago
  • Simplify versions
    By eschmar, 10 months ago
  • Update versioning constraints to symfony versions
    By eschmar, 10 months ago
  • Merge pull request #41 from eschmar/feature/tree-builder
    By web-flow, 10 months ago
  • Support also older versions
    By eschmar, 10 months ago
  • Not passing the root node name to TreeBuilder was deprecated
    By eschmar, 10 months ago
  • Fix symfony 4 versioning
    By eschmar, 1 year ago
  • Update for symfony 4
    By eschmar, 1 year ago
  • Update for symfony4
    By eschmar, 1 year ago
  • Symfony 3
    By eschmar, 1 year ago
  • Bump version
    By eschmar, 1 year ago
  • Fix languages
    By eschmar, 1 year ago
  • Fix german translation
    By eschmar, 1 year ago
  • Merge pull request #36 from lenybernard/fix-between-1-and-2-days
    By web-flow, 1 year ago
  • handle 1 day and translate for every locales
    By lenybernard, 1 year ago
  • Fix example
    By eschmar, 3 years ago
  • Merge pull request #35 from taufikherjanto/patch-1
    By web-flow, 3 years ago
  • Update messages.id.yml
    By web-flow, 3 years ago
  • Merge pull request #33 from eschmar/feature/refactor
    By web-flow, 3 years ago
  • Minor fixes
    By eschmar, 3 years ago
  • Merge pull request #32 from xiroV/danish_translation
    By web-flow, 3 years ago
  • Merge pull request #31 from od3n/develop
    By web-flow, 3 years ago
  • Added danish translation
    By xiroV, 3 years ago
  • Add Malay Translation
    By od3n, 3 years ago
  • Update languages
    By eschmar, 3 years ago