This project is archived and is in readonly mode.

#3266 ✓committed
John Trupiano

[PATCH] distance_of_time_in_words misleading for durations close to full years or close to 48 hours

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

This patch builds on top of #3106 ( 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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages