Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago'

#3106

When I think of a date that is "about 1 year ago" I think a year and a month ago or possibly a year and two months ago. However the math used in distance_of_time_in_words accounts for everything up to 1 minute short of two years as being "about a year ago" that means that 1 year 364 days 23 hours and 59 minutes is "about 1 year ago".

I feel dates up to 1 year and one month would better fit the category of "about 1 year ago" anything above that should fall into the "Over 1 year ago" category

Reported by Ben Fyvie · August 27th, 2009 @ 05:35 PM

State: committed
Milestone: none
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: none

Activity

  1. John Pignata
    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
    

    September 4th, 2009 @ 05:50 PM

  2. John Pignata
    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'

    September 18th, 2009 @ 04:14 AM

  3. John Pignata
    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.

    September 26th, 2009 @ 03:36 PM

  4. John Trupiano
    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."

    September 26th, 2009 @ 04:55 PM

  5. Lena Herrmann
    Lena Herrmann

    That's a +1 from me, I like it and it works as expected on 3.2.

    September 26th, 2009 @ 05:09 PM

  6. Lena Herrmann
  7. sr.iniv.t
    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.

    September 26th, 2009 @ 05:37 PM

  8. Dan Pickett
    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).

    September 26th, 2009 @ 05:38 PM

  9. John Trupiano
    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.

    September 26th, 2009 @ 05:41 PM

  10. John Trupiano
    John Trupiano

    Looking at this other example:

      distance_of_time_in_words(from_time, from_time + 50.minutes)        # => about 1 hour
    

    I'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
    

    September 26th, 2009 @ 05:52 PM

  11. Dan Pickett
  12. Dan Pickett
    Dan Pickett
    • Tag changed from action_view, bugmash, date_helper, patch to action_view, bugmash, bugmash-review, date_helper, patch

    September 26th, 2009 @ 05:56 PM

  13. John Trupiano
    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...

    September 26th, 2009 @ 09:16 PM

  14. Blue Box Jesse
    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"

    September 26th, 2009 @ 09:16 PM

  15. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from action_view, bugmash, bugmash-review, date_helper, patch to action_view, bugmash-review, date_helper, patch

    September 27th, 2009 @ 12:35 PM

  16. Matías Flores
    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.

    September 27th, 2009 @ 05:25 PM

  17. Repository
    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...

    September 28th, 2009 @ 03:29 AM

  18. Repository
    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...

    September 28th, 2009 @ 03:29 AM

  19. Rizwan Reza
    Rizwan Reza
    • Tag changed from action_view, bugmash-review, date_helper, patch to action_view, date_helper, patch

    May 15th, 2010 @ 06:42 PM