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

Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8708 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 b2fa70a8
*SVN*
* Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil [Geoff Buesing]
* Remove unneeded #to_datetime_default_s alias for DateTime#to_s, given that we inherit a #to_default_s from Date that does exactly the same thing [Geoff Buesing]
* Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else [Geoff Buesing]
......
......@@ -46,7 +46,7 @@ def in_time_zone(zone)
# Returns the simultaneous time in Time.zone
def in_current_time_zone
in_time_zone(::Time.zone)
::Time.zone ? in_time_zone(::Time.zone) : self
end
# Replaces the existing zone; leaves time value intact. Examples:
......@@ -60,7 +60,7 @@ def change_time_zone(zone)
# Replaces the existing zone to Time.zone; leaves time value intact
def change_time_zone_to_current
change_time_zone(::Time.zone)
::Time.zone ? change_time_zone(::Time.zone) : self
end
end
end
......
......@@ -170,8 +170,8 @@ def test_in_current_time_zone
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect
end
with_time_zone nil do
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.in_current_time_zone.inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.in_current_time_zone.inspect
assert_equal @t, @t.in_current_time_zone
assert_equal @dt, @dt.in_current_time_zone
end
end
......@@ -196,8 +196,8 @@ def test_change_time_zone_to_current
assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone_to_current.inspect
end
with_time_zone nil do
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone_to_current.inspect
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone_to_current.inspect
assert_equal @t, @t.change_time_zone_to_current
assert_equal @dt, @dt.change_time_zone_to_current
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册