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 misleading for durations close to full years or close to 48 hours

#3266

This patch builds on top of #3106 [PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago' ( https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets... ). Please apply that patch first if it has not already been merged into 2-3-stable.

It includes two parts:

Introduce :almost keyword for describing durations that are "almost a year long"

The new rules apply to durations greater than a year. Essentially we use "about" to describe durations that are 0-3 months greater than a whole year, "over" to describe durations that are 3-9 months greater than a whole year, and "almost" to describe durations 9-12 months greater than a whole year.

  • distance_of_time_in_words(now, now + 1.years + 9.months)
    • before: "over 1 year"
    • after: "almost 2 years"
  • distance_of_time_in_words(now, now + 2.years)
    • before: "about 2 years"
    • after: "about 2 years"
  • distance_of_time_in_words(now, now + 2.years + 3.months)
    • before: "about 2 years"
    • after: "over 2 years"
  • distance_of_time_in_words(now, now + 2.years + 9.months)
    • before: "over 2 years"
    • after: "almost 3 years"

Change how 1 day and 2 days are handled

  • distance_of_time_in_words(now, now + 47.hours)
    • before: "1 day"
    • after: "2 days"

For this one I used the same 3/4 ratio that is used for minutes to hours. At 45 minutes the text becomes "1 hour." At 1 day, 18 hours, the text becomes "2 days."

I also cleaned out a few unnecessary calls to #round. #round is only useful for floats, but there were a couple instances of it being called on ints.

Lastly, I updated the rdoc which had become stale.

Reported by John Trupiano · September 26th, 2009 @ 09:03 PM

State: committed
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. John Trupiano
  2. Matías Flores
    Matías Flores

    +1 verified patch applies cleanly in both master and 2-3-stable over patch in #3106 [PATCH] distance_of_time_in_words inaccurate for 'about 1 year ago'

    September 27th, 2009 @ 06:44 PM

  3. Gaius Centus Novus
  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from action_view, bugmash, date_helper, patch to action_view, bugmash-review, date_helper, patch

    September 28th, 2009 @ 01:32 AM

  5. Repository
    Repository
    • State changed from new to committed

    (from [c9318e9010712aeae33b1dd0e8bed4795ae37caf]) Introduce :almost keyword for distance_of_time_in_words. Make 1.75 days - 2 days return '2 days'.

    Signed-off-by: Michael Koziarski michael@koziarski.com
    [#3266 [PATCH] distance_of_time_in_words misleading for durations close to full year... state:committed] http://github.com/rails/rails/commit/c9318e9010712aeae33b1dd0e8bed4...

    September 28th, 2009 @ 03:29 AM

  6. Repository
  7. Rizwan Reza
    Rizwan Reza
    • Tag changed from action_view, bugmash-review, date_helper, patch to action_view, date_helper, patch

    May 15th, 2010 @ 06:37 PM