This project is archived and is in readonly mode.
[PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago'
-
John Pignata
I agree with this feature request in spirit as small and worthwhile, but it certainly requires discussion.
This patch enhances distance_of_time_in_words to prefix the year string with either "about" or "over" depending upon how many months have elapsed in that year. The logic here is that if the half year mark has been passed, the time string should be "over x years" while in the case where that mark has not been passed the "about x years" syntax should be used.
Examples:
distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year distance_of_time_in_words(from_time, from_time + 3.years + 6.months) # => over 3 years distance_of_time_in_words(from_time, from_time + 4.years + 9.days + 30.minutes + 5.seconds) # => about 4 years distance_of_time_in_words(from_time, from_time + 10.years + 2.days) # => about 10 years -
John Pignata
- Tag changed from action_view, date_helper to action_view, date_helper, patch
- Title changed from distance_of_time_in_words inaccurate for 'about 1 year ago' to [PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago'
-
John Pignata
- Tag changed from action_view, date_helper, patch to action_view, bugmash, date_helper, patch
Putting a bugmash tag on this to try to get this discussed. I know it's minor, but it's a bugaboo of mine that after an object exceeds a year in age, time_ago_in_words becomes obtuse.
-
John Trupiano
I'd be in favor of introducing the "almost" identifier as well. For instance, I'd think that distance_of_time_in_words(from_time, from_time + 3.years + 10.months) should return "almost 4 years" or "less than 4 years."
-
Lena Herrmann
That's a +1 from me, I like it and it works as expected on 3.2.
-
Lena Herrmann
... that means: verified.
-
sr.iniv.t
+1 from me too. 1.year + 11.months is certainly not "about 1 year ago". It makes sense to 'about' and 'over' prefixes.
Patch applies on 2-3-stable and works as expected.
-
Dan Pickett
John Trupiano,
I think you should create another ticket for the introduction of the "almost" identifier. I think that's more accurate than "over" given a certain threshold (say after 10 months).
-
John Trupiano
Dan, I was thinking at 9 months. In the general case, I was thinking that once it's past 3/4 the distance between the 2 whole values that we should switch to "almost the greater value."
Anyone else have thoughts? I'll start whipping up the patch.
-
John Trupiano
Looking at this other example:
distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hourI'd think we'd just keep with 'about' instead of 'almost', e.g.
distance_of_time_in_words(from_time, from_time + 3.years + 9.months) # => about 4 years -
Dan Pickett
+1 verified
-
Dan Pickett
- Tag changed from action_view, bugmash, date_helper, patch to action_view, bugmash, bugmash-review, date_helper, patch
-
John Trupiano
fyi, I created a separate ticket that builds on this patch as Dan Pickett suggested: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets...
-
Blue Box Jesse
Bug Mash +1
I think this is a valuable patch, but I also think that the wording of "over 3 years" isn't quite clear. To me, over 3 years seems to imply that the date could be 4, 5 or 6 years.
Logically, to me, I would think it would work like this:
1 year 0-6 months should be "about 1 year"
1 year 7-12 mo should be "almost 2 years" -
CancelProfileIsBroken
- Tag changed from action_view, bugmash, bugmash-review, date_helper, patch to action_view, bugmash-review, date_helper, patch
-
Matías Flores
- Tag changed from action_view, bugmash-review, date_helper, patch to action_view, bugmash-review, date_helper, patch
+1 verified John's patch applies cleanly in both master and 2-3-stable and all tests pass.
-
Repository
- State changed from new to committed
(from [b372b4c87515ab84e64028b437da1e047a128e4d]) Enhancing distance_of_time_in_words to prefix year output with over and about depending upon how many months have elapsed
Signed-off-by: Michael Koziarski michael@koziarski.com
[#3106 [PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago' state:committed] http://github.com/rails/rails/commit/b372b4c87515ab84e64028b437da1e... -
Repository
(from [8ef1cd9733cd12fc4e5ea25c149956a33fdffa70]) Enhancing distance_of_time_in_words to prefix year output with over and about depending upon how many months have elapsed
Signed-off-by: Michael Koziarski michael@koziarski.com
[#3106 [PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago' state:committed] http://github.com/rails/rails/commit/8ef1cd9733cd12fc4e5ea25c149956... -
Rizwan Reza
- Tag changed from action_view, bugmash-review, date_helper, patch to action_view, date_helper, patch
