Ticket #5617: handle_dst_changes_for_large_deltas_NEW_code.patch
| File handle_dst_changes_for_large_deltas_NEW_code.patch, 2.3 kB (added by rabiedenharn, 2 years ago) |
|---|
-
activesupport/lib/active_support/core_ext/time/calculations.rb
old new 25 25 26 26 # Seconds since midnight: Time.now.seconds_since_midnight 27 27 def seconds_since_midnight 28 self. hour.hours + self.min.minutes + self.sec+ (self.usec/1.0e+6)28 self.to_i - self.change(:hour => 0).to_i + (self.usec/1.0e+6) 29 29 end 30 30 31 31 # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options … … 56 56 # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension 57 57 # Do not use this method in combination with x.months, use months_ago instead! 58 58 def ago(seconds) 59 se conds.until(self)59 self.since(-seconds) 60 60 end 61 61 62 62 # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around 63 63 #the Numeric extension. Do not use this method in combination with x.months, use months_since instead! 64 64 def since(seconds) 65 seconds.since(self) 65 initial_dst = self.dst? ? 1 : 0 66 f = seconds.since(self) 67 final_dst = f.dst? ? 1 : 0 68 (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f 66 69 end 67 70 alias :in :since 68 71 … … 135 138 # Returns a new Time representing the start of the given day in next week (default is Monday). 136 139 def next_week(day = :monday) 137 140 days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} 138 # Adjust in case of switches to or from daylight savings time 139 week_from_today = self.since(1.week) + (self.since(1.week) <=> self).hour 140 week_from_today.beginning_of_week.since(days_into_week[day].day).change(:hour => 0) 141 since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) 141 142 end 142 143 143 144 # Returns a new Time representing the start of the day (0:00)