Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
captn3m0 opened this issue Jun 17, 2024 · 5 comments
Open

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

captn3m0 opened this issue Jun 17, 2024 · 5 comments

Comments

@captn3m0
Copy link
Contributor

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
Copy link
Owner

markets commented Jun 17, 2024

Hello @captn3m0 👋🏼

Maybe by using the "threshold" setting #24?

@captn3m0
Copy link
Contributor Author

captn3m0 commented Jun 17, 2024

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
Copy link
Contributor Author

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
Copy link
Owner

markets commented Jun 17, 2024

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:

def build_time_ago_slots(days_passed, depth, threshold, current_slots = [])
return current_slots if depth == 0 || days_passed == 0
range = days_to_range(days_passed)
days = days_in(range)
num_elems = (days_passed / days).to_i
current_slots << t(range, count: num_elems)
pending_days = days_passed - (num_elems * days)
if pending_days >= (days_passed * threshold).floor
build_time_ago_slots(pending_days, depth - 1, threshold, current_slots)
else
current_slots
end
end

@captn3m0
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants