diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-03-28 04:06:47 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-03-28 04:06:47 +0000 |
commit | 59183eec6f8d3e5d1ac5046dbd4f5cefc7041256 (patch) | |
tree | 223e06207adb97a74ebd84e43aee4c9b7c50a2af /activesupport/test | |
parent | 129d94477b1bb4478d1d8ceaed2a0f9a615e2d23 (diff) | |
download | rails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.tar.gz rails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.tar.bz2 rails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.zip |
Time.zone= accepts TZInfo::Timezone instances and Olson identifiers; wraps result in TimeZone instance
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9107 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 28 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 9 |
2 files changed, 37 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 5a645dc765..f20484666e 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -483,6 +483,34 @@ uses_tzinfo 'TimeWithZoneTest' do end end + def test_time_zone_setter_with_tzinfo_timezone_object_wraps_in_rails_time_zone + silence_warnings do # silence warnings raised by tzinfo gem + tzinfo = TZInfo::Timezone.get('America/New_York') + Time.zone = tzinfo + assert_kind_of TimeZone, Time.zone + assert_equal tzinfo, Time.zone.tzinfo + assert_equal 'America/New_York', Time.zone.name + assert_equal(-18_000, Time.zone.utc_offset) + end + end + + def test_time_zone_setter_with_tzinfo_timezone_identifier_does_lookup_and_wraps_in_rails_time_zone + silence_warnings do # silence warnings raised by tzinfo gem + Time.zone = 'America/New_York' + assert_kind_of TimeZone, Time.zone + assert_equal 'America/New_York', Time.zone.tzinfo.name + assert_equal 'America/New_York', Time.zone.name + assert_equal(-18_000, Time.zone.utc_offset) + end + end + + def test_time_zone_setter_with_non_identifying_argument_returns_nil + Time.zone = 'foo' + assert_equal nil, Time.zone + Time.zone = -15.hours + assert_equal nil, Time.zone + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 8dc71b5ba8..a87cbadc1c 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -192,6 +192,15 @@ class TimeZoneTest < Test::Unit::TestCase assert_equal Time.utc(1999,12,31,19), twz.time end end + + def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize + silence_warnings do # silence warnings raised by tzinfo gem + tzinfo = TZInfo::Timezone.get('America/New_York') + zone = TimeZone.create(tzinfo.name, nil, tzinfo) + assert_equal nil, zone.instance_variable_get('@utc_offset') + assert_equal(-18_000, zone.utc_offset) + end + end end def test_formatted_offset_positive |