luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.57k stars 156 forks source link

time_ago_in_words always rounds down #1649

Closed jwoertink closed 2 years ago

jwoertink commented 2 years ago
puts time_ago_in_words(110.minutes.ago) #=> an hour

It currently returns on hours because this is technically only 1 hour, but it ignores the other 50minutes. I would expect this to return "almost 2 hours" instead.

https://github.com/luckyframework/lucky/blob/e1a6adf8552676884e67528293d3142032387b4b/src/lucky/page_helpers/time_helpers.cr#L25

We do already make a special concession for minutes past 45 where we say "about an hour" if it's been 46minutes or more

https://github.com/luckyframework/lucky/blob/e1a6adf8552676884e67528293d3142032387b4b/src/lucky/page_helpers/time_helpers.cr#L77-L79

We could probably do the same here that if it's past X hour and 45 minutes, then just round up.

jwoertink commented 2 years ago

Also just to note how this works because I was a little surprised...

started = 110.minutes.ago
now = Time.utc

pp (now - started).minutes #=> 50

This doesn't give you the whole time in minutes. I think it basically sees the time as 1:50:00, and says "the minutes from this is 50".

robacarp commented 2 years ago

This is an unexpected feature of the #minutes method that has caught me off guard more than once. I think #total_minutes is what you want.

jwoertink commented 2 years ago

oh, look at that! I didn't even know that existed. Good find @robacarp