Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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)

Reverses the code change to *next_week* from #6483 and applies changes to *since* (and *ago*) and *seconds_since_midnight*

  • activesupport/lib/active_support/core_ext/time/calculations.rb

    old new  
    2525 
    2626        # Seconds since midnight: Time.now.seconds_since_midnight 
    2727        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) 
    2929        end 
    3030             
    3131        # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options 
     
    5656        # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension 
    5757        # Do not use this method in combination with x.months, use months_ago instead! 
    5858        def ago(seconds) 
    59           seconds.until(self
     59          self.since(-seconds
    6060        end 
    6161 
    6262        # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around  
    6363        #the Numeric extension. Do not use this method in combination with x.months, use months_since instead! 
    6464        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 
    6669        end 
    6770        alias :in :since 
    6871 
     
    135138        # Returns a new Time representing the start of the given day in next week (default is Monday). 
    136139        def next_week(day = :monday) 
    137140          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) 
    141142        end 
    142143         
    143144        # Returns a new Time representing the start of the day (0:00)