提交 29e33161 编写于 作者: G Geoff Buesing

Ensure correct TimeWithZone#to_date

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 ea285c2f
*SVN*
* Ensure correct TimeWithZone#to_date [Geoff Buesing]
* Make TimeWithZone work with tzinfo 0.2.x: use TZInfo::Timezone#zone_identifier alias for #abbreviation, silence warnings on tests. Raise LoadError when TZInfo version is < 0.2 by sniffing for TZInfo::TimeOrDateTime constant. Move all tzinfo-dependent TimeZone tests into uses_tzinfo block [Geoff Buesing]
* Time, DateTime and TimeWithZone #in_time_zone defaults to Time.zone. Removing now unneeded #in_current_time_zone [Geoff Buesing]
......
......@@ -139,7 +139,7 @@ def -(other)
end
end
%w(asctime day hour min mon sec usec wday yday year).each do |name|
%w(asctime day hour min mon sec usec wday yday year to_date).each do |name|
define_method(name) do
time.__send__(name)
end
......
......@@ -254,6 +254,19 @@ def test_to_i
def test_to_time
assert_equal @twz, @twz.to_time
end
def test_to_date
silence_warnings do # silence warnings raised by tzinfo gem
# 1 sec before midnight Jan 1 EST
assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 4, 59, 59), TimeZone['Eastern Time (US & Canada)'] ).to_date
# midnight Jan 1 EST
assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 5, 0, 0), TimeZone['Eastern Time (US & Canada)'] ).to_date
# 1 sec before midnight Jan 2 EST
assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 4, 59, 59), TimeZone['Eastern Time (US & Canada)'] ).to_date
# midnight Jan 2 EST
assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 5, 0, 0), TimeZone['Eastern Time (US & Canada)'] ).to_date
end
end
def test_to_datetime
silence_warnings do # silence warnings raised by tzinfo gem
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册