mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
Time#zone=, #in_time_zone and #change_time_zone accept a Duration
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8850 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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' }
|
||||
|
||||
Reference in New Issue
Block a user