markets / jekyll-timeago

⌛ Ruby library to compute distance of dates in words. Originally built for Jekyll.
MIT License
147 stars 26 forks source link

Avoid "and 4 weeks", or "and 12 months" #39

Open captn3m0 opened 3 months ago

captn3m0 commented 3 months ago

It is possible to get results that use "and 4 weeks", or "and 12 months". It would be better to round such usage up.

Jekyll::Timeago.timeago(Date.new(2024,8,15))
=> "in 1 month and 4 weeks"
Jekyll::Timeago.timeago(Date.new(2026,06,15))
=> "in 1 year and 12 months"
markets commented 3 months ago

Hello @captn3m0 👋🏼

Maybe by using the "threshold" setting https://github.com/markets/jekyll-timeago/pull/24?

captn3m0 commented 3 months ago

Yeah, I was thinking of adapting threshold as well for rounding up (current implementation only rounds down). I'll see if I can work on a PR.

captn3m0 commented 3 months ago

Also, this felt like a bug more than a feature request - "1 year and 12 months" should always be rounded up to 2 years, irrespective of a threshold.

markets commented 3 months ago

Also, this felt like a bug more than a feature request - "1 year and 12 months" should always be rounded up to 2 years, irrespective of a threshold.

Yes, I kind of agree with that. Is that also happening with no custom threshold at all 🤔?

For reference, all this logic is implemented in this method:

https://github.com/markets/jekyll-timeago/blob/f12f83392d657e46aee3df49fa0b2a03e91c5927/lib/jekyll-timeago/core.rb#L69-L85

captn3m0 commented 3 months ago

I did try with zero threshold, but just noticed I ran my tests in a repo with _config.yml that has a threshold set.

I'll double check in a clean environment and report back.