KnpLabs / KnpTimeBundle

Provides helpers for time manipulation
http://knplabs.com
MIT License
599 stars 107 forks source link

feat: add "age" formatter #190

Closed seb-jean closed 11 months ago

seb-jean commented 11 months ago

Hello,

Do you think it would be nice to add a feature to get the age?

For example :

{# with filter: #}
Age: {{ user.birthdate|age }} <!-- Age: 30 years old -->

{# ... or use the equivalent function: #}
Age: {{ age(user.birthdate) }} <!-- Age: 30 years old -->
Chris53897 commented 11 months ago

If the age() function get implemented, i suggest to add an optional parameter for a date. How old is the user on the given date?

now = 2000-08-02
startdateOfJourney = 2000-11-15

Age: {{ age(user.birthdate) }} <!-- Age: 22 years old -->
Age: {{ age(user.birthdate, startdateOfJourney) }} <!-- Age: 23 years old -->
kbond commented 11 months ago

I'm in favor of this feature!

Chris53897 commented 11 months ago

@seb-jean Would you be up for an PR?

seb-jean commented 11 months ago

Yes, i added #192