2017 © Pedro PelĂĄez
 

library time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

image

salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  • Monday, March 5, 2018
  • by Salavert
  • Repository
  • 6 Watchers
  • 83 Stars
  • 285,748 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 34 Forks
  • 2 Open issues
  • 12 Versions
  • 4 % Grown

The README.md

Time ago in words Twig extension

Packagist Build Status, (*1)

This is a Twig extension for Symfony Framework where you can easily convert a datetime/timestamp to a distance of time in words., (*2)

By example, (*3)

{{ user.lastLogin | time_ago_in_words }}

Outputs 3 days ago, (*4)

Installation for Symfony

1) Update your composer.json - #### Symfony 2/3 with Twig 1/2 json "require": { "salavert/time-ago-in-words": "1.*" }, (*5)

  or use composer's require command: `composer require salavert/time-ago-in-words:1.*`

- #### Symfony 4 with Twig 2/3
    ```json
    "require": {
        "salavert/time-ago-in-words": "2.*"
    }
    ```
  or use composer's require command: `composer require salavert/time-ago-in-words:2.*`

2) Register an Extension as a Service, (*6)

Now you must let the Service Container know about your newly created Twig Extension:, (*7)

YAML:, (*8)

# app/config/config.yml
services:
    salavert.twig.time_ago:
        class: Salavert\Twig\Extension\TimeAgoExtension
        arguments: ["@translator"]
        tags:
            - { name: twig.extension }

XML:, (*9)

# or into your bundle src\Acme\AcmeBundle\Resources\config\services.xml
<service id="salavert.twig.time_ago" class="Salavert\Twig\Extension\TimeAgoExtension">
    <tag name="twig.extension" />
    <argument type="service" id="translator" />
</service>

Usage

To display distance of time in words between a date and current date:, (*10)

{{ message.created | time_ago_in_words }}

To display distance of time between two custom dates you should use, (*11)

{{ message.created | distance_of_time_in_words(message.updated) }}

You also have two available options, for both time_ago_in_words & distance_of_time_in_words filters, (*12)

  • include_seconds (boolean) if you need more detailed seconds approximations if time is less than a minute
  • include_months (boolean) if you want days to be approximated in months if time is greater than 31 days.

Thus, if you want to have the months approximation but not the seconds one, you should use:, (*13)

{{ message.created | time_ago_in_words(false, true) }}

Translations

Add the following translations to your - \app\Resources\translations\messages.locale.yml or - \translations\messages.locale.yml, (*14)

This is a translation to spanish:, (*15)

# Time ago in words - Twig Extension
less than %seconds seconds ago: hace menos de %seconds segundos
half a minute ago: hace medio minuto
less than a minute ago: hace menos de un minuto
1 minute ago: hace 1 minuto
%minutes minutes ago: hace %minutes minutos
about 1 hour ago: hace casi 1 hora
about %hours hours ago: hace %hours horas
1 day ago: hace 1 dĂ­a
%days days ago: hace %days dĂ­as
"{1} 1 month ago |]1,Inf[ %months months ago": "{1} hace un mes |]1,Inf[ hace %months meses"
"{1} 1 year ago |]1,Inf[ %years years ago":  "hace un año |]1,Inf[ Hace %years años"

In the same case, for future:, (*16)

# Time ago in words - Twig Extension
in less than %seconds seconds: en menos de %seconds segundos
in half a minute: en medio minuto
in less than a minute: en menos de un minuto
in 1 minute: en 1 minuto
in %minutes minutes: en %minutes minutos
in about 1 hour: dentro de casi 1 hora
in about %hours hours: en %hours horas
in 1 day: en 1 dĂ­a
in %days days: en %days dĂ­as

Testing

To launch all tests first make sure dependecies are met with composer and run:, (*17)

./vendor/phpunit/phpunit/phpunit

The Versions

05/03 2018

dev-master

9999999-dev http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

05/03 2018

v1.7

1.7.0.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

30/06 2015

v1.6.2

1.6.2.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

19/06 2015

v1.6.1

1.6.1.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

19/06 2015

v1.6

1.6.0.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

03/05 2015

v1.5.3

1.5.3.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

The Development Requires

twig time time ago distance of time time ago in words

23/01 2015

v1.5.2

1.5.2.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time time ago distance of time time ago in words

23/01 2015

v1.5.1

1.5.1.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time time ago distance of time time ago in words

21/01 2015

v1.5

1.5.0.0 http://github.com/salavert/time-ago-in-words

Time ago Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time time ago distance of time time ago in words

19/06 2014

v1.4

1.4.0.0 http://github.com/salavert/time-ago-in-words

Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time ago distance of time time ago in words

27/08 2013

v1.3

1.3.0.0 http://github.com/salavert/time-ago-in-words

Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time ago distance of time time ago in words

28/05 2013

v1.0

1.0.0.0 http://github.com/salavert/time-ago-in-words

Twig extension where you can easily convert a datetime or timestamp to a distance of time in words.

  Sources   Download

MIT

The Requires

 

twig time ago distance of time time ago in words