diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 02:46:47 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-01-23 02:46:47 +0000 |
commit | abb24b484fcb306be17dd06a8a2d12ca5a035aeb (patch) | |
tree | 96de38f875c4048b27e6fae61de0d00111a66014 /activesupport/test | |
parent | 2e7b2f03448e5759113ce0c182ed99897342c7a9 (diff) | |
download | rails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.tar.gz rails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.tar.bz2 rails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.zip |
Adding Time and DateTime #formatted_offset, for outputting +HH:MM utc offset strings with cross-platform consistency
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8698 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 12 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 15 |
2 files changed, 27 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 f69bdba127..768ea281d3 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -241,6 +241,18 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase 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 + + def test_formatted_offset_with_utc + assert_equal '+00:00', DateTime.civil(2000).formatted_offset + assert_equal '+0000', DateTime.civil(2000).formatted_offset(false) + assert_equal 'UTC', DateTime.civil(2000).formatted_offset(true, 'UTC') + end + + def test_formatted_offset_with_local + dt = DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)) + assert_equal '-05:00', dt.formatted_offset + assert_equal '-0500', dt.formatted_offset(false) + end protected def with_timezone(new_tz = 'US/Eastern') diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 5970411233..e9c7a1ed79 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -409,6 +409,21 @@ class TimeExtCalculationsTest < Test::Unit::TestCase def test_acts_like_time assert Time.new.acts_like_time? end + + def test_formatted_offset_with_utc + assert_equal '+00:00', Time.utc(2000).formatted_offset + assert_equal '+0000', Time.utc(2000).formatted_offset(false) + assert_equal 'UTC', Time.utc(2000).formatted_offset(true, 'UTC') + end + + def test_formatted_offset_with_local + with_timezone 'US/Eastern' do + assert_equal '-05:00', Time.local(2000).formatted_offset + assert_equal '-0500', Time.local(2000).formatted_offset(false) + assert_equal '-04:00', Time.local(2000, 7).formatted_offset + assert_equal '-0400', Time.local(2000, 7).formatted_offset(false) + end + end protected def with_timezone(new_tz = 'US/Eastern') |