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

time_ago_in_words reports the wrong number of months. #3560

Closed
miskander opened this issue Nov 8, 2011 · 2 comments
Closed

time_ago_in_words reports the wrong number of months. #3560

miskander opened this issue Nov 8, 2011 · 2 comments

Comments

@miskander
Copy link

As seen below, time_ago_in_words reports about 1 month ago for an almost 2 month difference. I think this needs to be more precise and say less than 2 months ago or something indicating that it is over a month.

$ rails -v
Rails 3.0.9
irb(main):002:0> require 'rubygems'
=> nil
irb(main):003:0> require 'action_view'
=> nil
irb(main):004:0> include ActionView::Helpers::DateHelper
=> Object
irb(main):002:0> require 'rubygems'
=> nil
irb(main):003:0> require 'action_view'
=> nil
irb(main):004:0> include ActionView::Helpers::DateHelper
=> Object
irb(main):005:0> a=Date.new(2011, 9, 9)
=> Fri, 09 Sep 2011
irb(main):006:0> time_ago_in_words(a)
=> "about 1 month"
irb(main):007:0> Date.today
=> Mon, 07 Nov 2011

@HectorMalot
Copy link

That does seem to be misrepresenting the date. Perhaps it could be:
30 days .. 45 days => about 1 month
45 days .. 60 days => about 2 months
61 days plus => current behaviour

I think this change should make that possible:

# actionpack/lib/action_view/helpers/date_helper.rb:94
when 43200..64799    then locale.t :about_x_months, :count => 1
when 64800..86399    then locale.t :about_x_months, :count => 2

Another option (in my opinion) would be to count weeks, as in: 4 weeks, 5 weeks, 6 weeks, about 2 months, etc. The main issue here seems to be that 'about 1 month' is considered to course, and I must admit, its quite a step from "about x days" to "about x months". Counting in weeks would solve that.

If people agree I'm willing to try and make my first pull request for rails. 👍

@mcmire
Copy link
Contributor

mcmire commented Feb 26, 2012

I've added a fix for this in #5181. I changed that line so that instead of :count => 1 it's :count => (minutes rounded to the nearest hour). So this does exactly what you had in mind: 30-45 days is 1 month, 45-60 days is two months.

@jeremy jeremy closed this as completed in b7ec875 Apr 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants