mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix #distance_of_time_in_words to report accurately against the Duration class. #7114 [eventualbuddha]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5973 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
1ff84503b4
commit
4733182e56
3 changed files with 10 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Fix #distance_of_time_in_words to report accurately against the Duration class. #7114 [eventualbuddha]
|
||||
|
||||
* Refactor #form_tag to allow easy extending. [Rick]
|
||||
|
||||
* Update to Prototype 1.5.0. [Sam Stephenson]
|
||||
|
|
|
@ -69,9 +69,9 @@ module ActionView
|
|||
when 1440..2879 then '1 day'
|
||||
when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
|
||||
when 43200..86399 then 'about 1 month'
|
||||
when 86400..525959 then "#{(distance_in_minutes / 43200).round} months"
|
||||
when 525960..1051919 then 'about 1 year'
|
||||
else "over #{(distance_in_minutes / 525960).round} years"
|
||||
when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
|
||||
when 525600..1051199 then 'about 1 year'
|
||||
else "over #{(distance_in_minutes / 525600).round} years"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class DateHelperTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_distance_in_words
|
||||
from = Time.mktime(2004, 3, 6, 21, 45, 0)
|
||||
from = Time.mktime(2004, 6, 6, 21, 45, 0)
|
||||
|
||||
# 0..1 with include_seconds
|
||||
assert_equal "less than 5 seconds", distance_of_time_in_words(from, from + 0.seconds, true)
|
||||
|
@ -64,16 +64,16 @@ class DateHelperTest < Test::Unit::TestCase
|
|||
assert_equal "about 1 month", distance_of_time_in_words(from, from + 29.days + 23.hours + 59.minutes + 30.seconds)
|
||||
assert_equal "about 1 month", distance_of_time_in_words(from, from + 59.days + 23.hours + 59.minutes + 29.seconds)
|
||||
|
||||
# 86400..525959
|
||||
# 86400..525599
|
||||
assert_equal "2 months", distance_of_time_in_words(from, from + 59.days + 23.hours + 59.minutes + 30.seconds)
|
||||
assert_equal "12 months", distance_of_time_in_words(from, from + 1.years - 31.seconds)
|
||||
|
||||
# 525960..1051919
|
||||
# 525600..1051199
|
||||
assert_equal "about 1 year", distance_of_time_in_words(from, from + 1.years - 30.seconds)
|
||||
assert_equal "about 1 year", distance_of_time_in_words(from, from + 2.years - 31.seconds)
|
||||
|
||||
# > 1051920
|
||||
assert_equal "over 2 years", distance_of_time_in_words(from, from + 2.years - 30.seconds)
|
||||
# > 1051199
|
||||
assert_equal "over 2 years", distance_of_time_in_words(from, from + 2.years + 30.seconds)
|
||||
assert_equal "over 10 years", distance_of_time_in_words(from, from + 10.years)
|
||||
|
||||
# test to < from
|
||||
|
|
Loading…
Reference in a new issue