Permalink
Browse files

Enhance testing for fractional days and weeks. Update changelog.

  • Loading branch information...
gbuesing committed Oct 14, 2008
1 parent a6e5d29 commit c51db4d7ababd6f1c341d2808a298865ee449313
View
@@ -1,5 +1,7 @@
*Edge*
* Time#advance recognizes fractional days and weeks. Deprecate Durations of fractional months and years #970 [Tom Lea]
* Add ActiveSupport::Rescuable module abstracting ActionController::Base rescue_from features. [Norbert Crombach, Pratik]
* Switch from String#chars to String#mb_chars for the unicode proxy. [Manfred Stienstra]
@@ -30,21 +30,17 @@ def test_argument_error
end
end
uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do
def test_fractional_weeks
Time.stubs(:now).returns Time.local(2000)
assert_in_delta((24 * 7 * 1.5).hours, 1.5.weeks, 2 ** -20)
assert_in_delta((24 * 7 * 1.7).hours, 1.7.weeks, 2 ** -20)
end
def test_fractional_days
Time.stubs(:now).returns Time.local(2000)
def test_fractional_weeks
assert_equal (86400 * 7) * 1.5, 1.5.weeks
assert_equal (86400 * 7) * 1.7, 1.7.weeks
end
assert_in_delta((24 * 1.5).hours, 1.5.days, 2 ** -20)
assert_in_delta((24 * 1.7).hours, 1.7.days, 2 ** -20)
end
def test_fractional_days
assert_equal 86400 * 1.5, 1.5.days
assert_equal 86400 * 1.7, 1.7.days
end
uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do
def test_since_and_ago_with_fractional_days
Time.stubs(:now).returns Time.local(2000)
# since
@@ -381,7 +381,11 @@ def test_advance
assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1)
assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4)
assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3)
assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5)
assert_equal Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7)
assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5)
assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5)
assert_equal Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7)
assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7)
assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5)
assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5)
@@ -399,7 +403,11 @@ def test_utc_advance
assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1)
assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4)
assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3)
assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5)
assert_equal Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7)
assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5)
assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5)
assert_equal Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7)
assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7)
assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11)
assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5)

0 comments on commit c51db4d

Please sign in to comment.