aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-04-04 03:29:30 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-04-04 03:29:30 +0000
commit49f2e6f8d4002185b53f7108463a50b55e4aa86e (patch)
tree2f43d44693b525502c9dd9bb143029f112c68be4
parentcfe42ba1b19c5ee96a268dbb85cece16c0cc354b (diff)
downloadrails-49f2e6f8d4002185b53f7108463a50b55e4aa86e.tar.gz
rails-49f2e6f8d4002185b53f7108463a50b55e4aa86e.tar.bz2
rails-49f2e6f8d4002185b53f7108463a50b55e4aa86e.zip
Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9221 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb4
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb52
3 files changed, 56 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 587cb28522..b2955ab69d 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone]
+
* TimeWithZone: Adding tests for dst and leap day edge cases when advancing time [Geoff Buesing]
* TimeWithZone#method_missing: send to utc to advance with dst correctness, otherwise send to time. Adding tests for time calculations methods [Geoff Buesing]
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 867ac86617..0bc83af709 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -221,12 +221,12 @@ module ActiveSupport #:nodoc:
# Convenience method which returns a new Time representing the time 1 day ago
def yesterday
- self.ago(1.day)
+ advance(:days => -1)
end
# Convenience method which returns a new Time representing the time 1 day since the instance time
def tomorrow
- self.since(1.day)
+ advance(:days => 1)
end
def plus_with_duration(other) #:nodoc:
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index fd5ca5aa55..d1d92964c3 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -227,6 +227,32 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
+ def test_daylight_savings_time_crossings_forward_start_tomorrow
+ with_env_tz 'US/Eastern' do
+ # st: US: 2005 April 2nd 7:27pm
+ assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).tomorrow, 'st+1.day=>dt'
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).tomorrow, 'dt+1.day=>dt'
+ end
+ with_env_tz 'NZ' do
+ # st: New Zealand: 2006 September 30th 7:27pm
+ assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).tomorrow, 'st+1.day=>dt'
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).tomorrow, 'dt+1.day=>dt'
+ end
+ end
+
+ def test_daylight_savings_time_crossings_forward_start_yesterday
+ with_env_tz 'US/Eastern' do
+ # st: US: 2005 April 2nd 7:27pm
+ assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st'
+ assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,4,19,27,0).yesterday, 'dt-1.day=>dt'
+ end
+ with_env_tz 'NZ' do
+ # st: New Zealand: 2006 September 30th 7:27pm
+ assert_equal Time.local(2006,9,30,19,27,0), Time.local(2006,10,1,19,27,0).yesterday, 'dt-1.day=>st'
+ assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,10,2,19,27,0).yesterday, 'dt-1.day=>dt'
+ end
+ end
+
def test_daylight_savings_time_crossings_forward_end
with_env_tz 'US/Eastern' do
# dt: US: 2005 October 30th 12:45am
@@ -240,6 +266,32 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
+ def test_daylight_savings_time_crossings_forward_end_tomorrow
+ with_env_tz 'US/Eastern' do
+ # dt: US: 2005 October 30th 12:45am
+ assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).tomorrow, 'dt+1.day=>st'
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).tomorrow, 'st+1.day=>st'
+ end
+ with_env_tz 'NZ' do
+ # dt: New Zealand: 2006 March 19th 1:45am
+ assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).tomorrow, 'dt+1.day=>st'
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).tomorrow, 'st+1.day=>st'
+ end
+ end
+
+ def test_daylight_savings_time_crossings_forward_end_yesterday
+ with_env_tz 'US/Eastern' do
+ # dt: US: 2005 October 30th 12:45am
+ assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt'
+ assert_equal Time.local(2005,10, 31,0,45,0), Time.local(2005,11,1,0,45,0).yesterday, 'st-1.day=>st'
+ end
+ with_env_tz 'NZ' do
+ # dt: New Zealand: 2006 March 19th 1:45am
+ assert_equal Time.local(2006,3,19,1,45,0), Time.local(2006,3,20,1,45,0).yesterday, 'st-1.day=>dt'
+ assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,21,1,45,0).yesterday, 'st-1.day=>st'
+ end
+ end
+
def test_yesterday
assert_equal Time.local(2005,2,21,10,10,10), Time.local(2005,2,22,10,10,10).yesterday
assert_equal Time.local(2005,2,28,10,10,10), Time.local(2005,3,2,10,10,10).yesterday.yesterday