aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-22 18:43:36 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-22 18:43:36 +0000
commit29e33161784dae84b1e92f9acf9db7d0f1d0da64 (patch)
tree5ad2286673d14b79f2896efb0c817c8e9809809d /activesupport
parentea285c2f783f4f06918b9c5f5956cf4d5c5e5e25 (diff)
downloadrails-29e33161784dae84b1e92f9acf9db7d0f1d0da64.tar.gz
rails-29e33161784dae84b1e92f9acf9db7d0f1d0da64.tar.bz2
rails-29e33161784dae84b1e92f9acf9db7d0f1d0da64.zip
Ensure correct TimeWithZone#to_date
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb2
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb13
3 files changed, 16 insertions, 1 deletions
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