From 0f5f05b51ec7a90d9eeb1592df9c497b190f15a0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 24 Oct 2006 23:35:27 +0000 Subject: next_week respects DST changes. Closes #6483. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5363 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/time/calculations.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/time') 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) -- cgit v1.2.3