Permalink
Browse files

Merge pull request #10406 from greenriver/distance_of_time_rational

Correct time_ago_in_words to handle situation where Fixnum#/ returns a Rational (thanks to mathn)
  • Loading branch information...
2 parents 3c01a69 + 5a6d9d5 commit fb90ce015f5ba0919d1546a77ac65ca2c3539a74 @rafaelfranca rafaelfranca committed May 6, 2013
@@ -112,7 +112,7 @@ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, o
# english it would read better as about 80 years.
minutes_with_offset = distance_in_minutes - minute_offset_for_leap_year
remainder = (minutes_with_offset % 525600)
- distance_in_years = (minutes_with_offset / 525600)
+ distance_in_years = (minutes_with_offset.div 525600)
if remainder < 131400
locale.t(:about_x_years, :count => distance_in_years)
elsif remainder < 394200
@@ -19,6 +19,8 @@ def to_param
end
def assert_distance_of_time_in_words(from, to=nil)
+ Fixnum.send :private, :/ # test we avoid Integer#/ (redefined by mathn)
+
to ||= from
# 0..1 with include_seconds
@@ -96,6 +98,9 @@ def assert_distance_of_time_in_words(from, to=nil)
# test to < from
assert_equal "about 4 hours", distance_of_time_in_words(from + 4.hours, to)
assert_equal "less than 20 seconds", distance_of_time_in_words(from + 19.seconds, to, true)
+
+ ensure
+ Fixnum.send :public, :/
end
def test_distance_in_words

0 comments on commit fb90ce0

Please sign in to comment.