From 29e33161784dae84b1e92f9acf9db7d0f1d0da64 Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Sat, 22 Mar 2008 18:43:36 +0000 Subject: Ensure correct TimeWithZone#to_date git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/time_with_zone.rb | 2 +- activesupport/test/core_ext/time_with_zone_test.rb | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 651da81eb1..cb04c4d234 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *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] diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 5933fc9667..7b9b121a17 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -139,7 +139,7 @@ module ActiveSupport 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 diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 3bc1e3920a..fc4f61dd37 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -254,6 +254,19 @@ uses_tzinfo 'TimeWithZoneTest' do 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 -- cgit v1.2.3