diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 22:22:36 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 22:22:36 +0000 |
commit | ac03ad1f78d88f40924225089a4b4bfebc8c74d8 (patch) | |
tree | e5216e3eb9b7eed0299b6d9dd1b432fd4a68b4c7 /activesupport/test/core_ext/time_with_zone_test.rb | |
parent | 213fac6f49532e7ee08348542e80465088b9bf5d (diff) | |
download | rails-ac03ad1f78d88f40924225089a4b4bfebc8c74d8.tar.gz rails-ac03ad1f78d88f40924225089a4b4bfebc8c74d8.tar.bz2 rails-ac03ad1f78d88f40924225089a4b4bfebc8c74d8.zip |
Adding Time and DateTime #compare_with_coercion, which layers behavior on #<=> so that any combination of Time, DateTime and ActiveSupport::TimeWithZone instances can be chronologically compared
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8711 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/time_with_zone_test.rb')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 55f41e0715..982384fac8 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -87,12 +87,24 @@ uses_tzinfo 'TimeWithZoneTest' do def test_xmlschema assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema end - - def test_compare + + def test_compare_with_time assert_equal 1, @twz <=> Time.utc(1999, 12, 31, 23, 59, 59) - assert_equal 0, @twz <=> Time.utc(2000) + assert_equal 0, @twz <=> Time.utc(2000, 1, 1, 0, 0, 0) assert_equal(-1, @twz <=> Time.utc(2000, 1, 1, 0, 0, 1)) end + + def test_compare_with_datetime + assert_equal 1, @twz <=> DateTime.civil(1999, 12, 31, 23, 59, 59) + assert_equal 0, @twz <=> DateTime.civil(2000, 1, 1, 0, 0, 0) + assert_equal(-1, @twz <=> DateTime.civil(2000, 1, 1, 0, 0, 1)) + end + + def test_compare_with_time_with_zone + assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59) ) + assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0) ) + assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1) )) + end def test_plus assert_equal Time.utc(1999, 12, 31, 19, 0 ,5), (@twz + 5).time |