diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-01-16 20:07:10 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-01-16 20:07:10 +0000 |
commit | 47ff3aa91ff23ae8676717519fe0aecd1f6a7d82 (patch) | |
tree | bb952c8585df25501500fdf59ebcc6fe35044c08 /activesupport/test | |
parent | 61e550ade937f812546b6fe561bc5ceb4460b9fb (diff) | |
download | rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.tar.gz rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.tar.bz2 rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.zip |
Introducing DateTime #utc, #utc? and #utc_offset, for duck-typing compatibility with Time. Closes #10002
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8649 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 4fa1b5aafd..f69bdba127 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -219,6 +219,28 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase assert_equal Rational(-6, 24), DateTime.local_offset end end + + def test_utc? + assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12).utc? + assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc? + assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, 0.25).utc? + assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc? + end + + def test_utc_offset + assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12).utc_offset + assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc_offset + assert_equal 21600, DateTime.civil(2005, 2, 21, 10, 11, 12, 0.25).utc_offset + assert_equal( -21600, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc_offset ) + assert_equal( -18000, DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc_offset ) + end + + def test_utc + assert_equal DateTime.civil(2005, 2, 21, 16, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc + assert_equal DateTime.civil(2005, 2, 21, 15, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc + assert_equal DateTime.civil(2005, 2, 21, 10, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc + assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).utc + end protected def with_timezone(new_tz = 'US/Eastern') |