diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-10-24 23:35:27 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-10-24 23:35:27 +0000 |
commit | 0f5f05b51ec7a90d9eeb1592df9c497b190f15a0 (patch) | |
tree | 829bf284e920606c15c2143e3cf677d08dceb399 | |
parent | d54c1b517d98e62c0beb14352f3d7c2e89df1ce6 (diff) | |
download | rails-0f5f05b51ec7a90d9eeb1592df9c497b190f15a0.tar.gz rails-0f5f05b51ec7a90d9eeb1592df9c497b190f15a0.tar.bz2 rails-0f5f05b51ec7a90d9eeb1592df9c497b190f15a0.zip |
next_week respects DST changes. Closes #6483.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5363 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 26286cecfb..8b7d421473 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* next_week respects DST changes. #6483 [marclove] + * Expose methods added to Enumerable in the documentation, such as group_by. Closes #6170. [sergeykojin@gmail.com, Marcel Molina Jr.] * Ensure Chars#tidy_bytes only tidies broken bytes. Closes #6397 [Manfred Stienstra] diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 8511a74d5c..cfad5c5986 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -135,7 +135,9 @@ module ActiveSupport #:nodoc: # Returns a new Time representing the start of the given day in next week (default is Monday). def next_week(day = :monday) days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} - since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) + # Adjust in case of switches to or from daylight savings time + week_from_today = self.since(1.week) + (self.since(1.week) <=> self).hour + week_from_today.beginning_of_week.since(days_into_week[day].day).change(:hour => 0) end # Returns a new Time representing the start of the day (0:00) diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index ab76348967..dc58401c3e 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -146,6 +146,8 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,2,28), Time.local(2005,2,22,15,15,10).next_week assert_equal Time.local(2005,2,29), Time.local(2005,2,22,15,15,10).next_week(:tuesday) assert_equal Time.local(2005,3,4), Time.local(2005,2,22,15,15,10).next_week(:friday) + assert_equal Time.local(2006,10,30), Time.local(2006,10,23,0,0,0).next_week + assert_equal Time.local(2006,11,1), Time.local(2006,10,23,0,0,0).next_week(:wednesday) end def test_to_s |