提交 b9be374d 编写于 作者: G Geoff Buesing

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
上级 db4fc6f2
*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 @@ def use_zone(time_zone)
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 @@ def test_in_time_zone
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 @@ def test_change_time_zone
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 @@ def test_use_zone_with_exception_raised
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' }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册