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

Add precision to DateTime.Humanize #101

Closed
MehdiK opened this issue Mar 13, 2014 · 4 comments
Closed

Add precision to DateTime.Humanize #101

MehdiK opened this issue Mar 13, 2014 · 4 comments
Milestone

Comments

@MehdiK
Copy link
Member

MehdiK commented Mar 13, 2014

e.g. (55 days).Humanize(precision:5) => "2 months" (instead of one month)

We also need to apply a sensible default based on each unit; e.g.

  • 5 for days so 55 days reports as 2 months
  • 2 for months so 22 months reports as 2 years

Also perhaps these defaults should be lower for singular units; e.g. 25 days shouldn't report as one month; but 29 days perhaps could report as one month while 55 days reports as 2 months! A bit unsure about this as it might get a bit confusing.

Either way this is a breaking change and as such set for V2.

@MehdiK MehdiK added this to the V2 milestone Mar 13, 2014
@wahidshalaly
Copy link
Contributor

I think it can be better if we defined precision as percentage. Let's say by default precision = 0.75 if someone prefers to override it to be either 0.5 or 0.95 for example, that's fine.

0.75 of a minute => if (delta >= 45 seconds) => about a minute
0.75 of a day => if (delta >= 18 hours) => about a day
0.75 of month (30 days) => if (delta >= 22.5 days) => about a month
0.75 of year (365 days) => if (delta >= 273.75 days) => about a year

There's another place we can examine for ideas.. Ruby::ActionView::Helpers::DateHelper distance_of_time_in_words

@MehdiK
Copy link
Member Author

MehdiK commented Mar 14, 2014

That's a great idea @waheedsayed. Thanks.

By breaking change I didn't mean API breaking change but behavioural. After this change the call that would previously return "a few hours ago" will return "yesterday" and that's a breaking change from my point of view.

I think we could implement this and set the default to 1 for now, and as part of V2 we could decrease it a bit.

@MehdiK
Copy link
Member Author

MehdiK commented Apr 3, 2014

After reading through #114 by @waheedsayed, it turns out the current implementation is precision based but the (.75) precision is precalculated and hardcoded on each time unit! So we can replace the existing algorithm with the one created in #114.

@MehdiK
Copy link
Member Author

MehdiK commented Apr 10, 2014

Done in #165

@MehdiK MehdiK closed this as completed Apr 10, 2014
@clairernovotny clairernovotny mentioned this issue Dec 18, 2015
12 tasks
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

Successfully merging a pull request may close this issue.

2 participants