aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb3
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb24
3 files changed, 28 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index b10c9614d8..c132e5372a 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Time#zone=, #in_time_zone and #change_time_zone accept a Duration [Geoff Buesing]
+
* Time#in_time_zone handles Time.local instances correctly [Geoff Buesing]
* Pruning unneeded Time#change_time_zone_to_current. Enhanced docs to #change_time_zone to explain the difference between this method and #in_time_zone [Geoff Buesing]
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb
index 18af28edc8..1fab89be48 100644
--- a/activesupport/lib/active_support/core_ext/time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/time/zones.rb
@@ -38,7 +38,8 @@ module ActiveSupport #:nodoc:
private
def get_zone(time_zone)
- ::String === time_zone || ::Numeric === time_zone ? TimeZone[time_zone] : time_zone
+ return time_zone if time_zone.nil? || time_zone.respond_to?(:period_for_local)
+ TimeZone[time_zone]
end
end
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 14a96169dd..cc7a55b2ee 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -171,6 +171,7 @@ uses_tzinfo 'TimeWithZoneTest' do
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_time_zone('Hawaii').inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.in_time_zone('UTC').inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.in_time_zone('UTC').inspect
+ assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone(-9.hours).inspect
end
end
end
@@ -208,6 +209,7 @@ uses_tzinfo 'TimeWithZoneTest' do
assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone('Hawaii').inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone('UTC').inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone('UTC').inspect
+ assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone(-9.hours).inspect
end
end
end
@@ -228,6 +230,28 @@ uses_tzinfo 'TimeWithZoneTest' do
assert_equal TimeZone['Alaska'], Time.zone
end
+ def test_time_zone_getter_and_setter
+ Time.zone = TimeZone['Alaska']
+ assert_equal TimeZone['Alaska'], Time.zone
+ Time.zone = 'Alaska'
+ assert_equal TimeZone['Alaska'], Time.zone
+ Time.zone = -9.hours
+ assert_equal TimeZone['Alaska'], Time.zone
+ Time.zone = nil
+ assert_equal nil, Time.zone
+ end
+
+ def test_time_zone_getter_and_setter_with_zone_default
+ Time.zone_default = TimeZone['Alaska']
+ assert_equal TimeZone['Alaska'], Time.zone
+ Time.zone = TimeZone['Hawaii']
+ assert_equal TimeZone['Hawaii'], Time.zone
+ Time.zone = nil
+ assert_equal TimeZone['Alaska'], Time.zone
+ ensure
+ Time.zone_default = nil
+ end
+
def test_time_zone_setter_is_thread_safe
Time.use_zone 'Paris' do
t1 = Thread.new { Time.zone = 'Alaska' }