Permalink
Browse files

Ensure correct TimeWithZone#to_date

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent ea285c2 commit 29e33161784dae84b1e92f9acf9db7d0f1d0da64 @gbuesing gbuesing committed Mar 22, 2008
View
@@ -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]
@@ -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

0 comments on commit 29e3316

Please sign in to comment.