diff options
Diffstat (limited to 'activesupport/test/core_ext')
-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') |