Is there a different time calculation in rails besides "time_ago_in_words"?? I want to be able to use just 'h' for hours 'd' days 'm' for months... ex. 3d, or 4h, or 5m
My code now...
<%= time_ago_in_words(feed_item.created_at) %> ago.
In the newer versions of rails, you can specify a scope as an option for the method like so:
time_ago_in_words(company.updated_at, scope: 'datetime.distance_in_words.abbrv')
Then you just need to have your regular i18n file structured like so:
en:
datetime:
distance_in_words:
abbrv:
about_x_hours:
one: ~ 1h
other: ~ %{count}h
about_x_months:
one: ~ 1mo
other: ~ %{count}mo
about_x_years:
one: ~ 1y
other: ~ %{count}y
almost_x_years:
...
This information is also available in the documentation: https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With