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

Ticket #6483: next_week_dst_compatibility.patch

File next_week_dst_compatibility.patch, 1.7 kB (added by marclove, 2 years ago)
  • activesupport/lib/active_support/core_ext/time/calculations.rb

    old new  
    135135        # Returns a new Time representing the start of the given day in next week (default is Monday). 
    136136        def next_week(day = :monday) 
    137137          days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} 
    138           since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) 
     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) 
    139141        end 
    140142         
    141143        # Returns a new Time representing the start of the day (0:00) 
  • activesupport/test/core_ext/time_ext_test.rb

    old new  
    146146    assert_equal Time.local(2005,2,28), Time.local(2005,2,22,15,15,10).next_week 
    147147    assert_equal Time.local(2005,2,29), Time.local(2005,2,22,15,15,10).next_week(:tuesday) 
    148148    assert_equal Time.local(2005,3,4), Time.local(2005,2,22,15,15,10).next_week(:friday) 
     149    assert_equal Time.local(2006,10,30), Time.local(2006,10,23,0,0,0).next_week 
     150    assert_equal Time.local(2006,11,1), Time.local(2006,10,23,0,0,0).next_week(:wednesday) 
    149151  end 
    150152 
    151153  def test_to_s