diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-02 01:52:11 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-02 01:52:11 +0000 |
commit | 5ba85d84fb3d18d28a3a6bc801286aad09f42014 (patch) | |
tree | a269a19a436372f59f98cf9e4d34f38b56a56127 /activesupport/lib/active_support | |
parent | 5cc682da0786478e95a7fde04fafa69808341efb (diff) | |
download | rails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.tar.gz rails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.tar.bz2 rails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.zip |
next_week respects DST changes. Closes #5617, closes #2353, closes #2509, references #4551.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5388 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index cfad5c5986..fb82513047 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -25,7 +25,7 @@ module ActiveSupport #:nodoc: # Seconds since midnight: Time.now.seconds_since_midnight def seconds_since_midnight - self.hour.hours + self.min.minutes + self.sec + (self.usec/1.0e+6) + self.to_i - self.change(:hour => 0).to_i + (self.usec/1.0e+6) end # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options @@ -56,13 +56,16 @@ module ActiveSupport #:nodoc: # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension # Do not use this method in combination with x.months, use months_ago instead! def ago(seconds) - seconds.until(self) + self.since(-seconds) end # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around #the Numeric extension. Do not use this method in combination with x.months, use months_since instead! def since(seconds) - seconds.since(self) + initial_dst = self.dst? ? 1 : 0 + f = seconds.since(self) + final_dst = f.dst? ? 1 : 0 + (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f end alias :in :since @@ -135,9 +138,7 @@ 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} - # 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) + since(1.week).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) |