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

Ticket #9818: time_and_datetime_advance_ignore_invalid_options.diff

File time_and_datetime_advance_ignore_invalid_options.diff, 4.4 kB (added by gbuesing, 11 months ago)
  • test/core_ext/time_ext_test.rb

    old new  
    233233    assert_equal Time.utc(2005,2,22,15,45),    Time.utc(2005,2,22,15,15,10).change(:min => 45) 
    234234  end 
    235235 
    236   def test_plus 
     236  def test_advance 
    237237    assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1) 
    238238    assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) 
    239239    assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) 
     
    241241    assert_equal Time.local(2005,2,28,15,15,10), Time.local(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year 
    242242  end 
    243243 
    244   def test_utc_plus 
     244  def test_utc_advance 
    245245    assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) 
    246246    assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) 
    247247    assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) 
    248248    assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11) 
    249249    assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year 
    250250  end 
     251   
     252  def test_advance_ignores_invalid_options 
     253    assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1, :hour => 3, :min => 4, :sec => 5, :usec => 6, :foo => 19) 
     254  end 
    251255 
    252256  def test_next_week 
    253257    with_timezone 'US/Eastern' do 
  • test/core_ext/date_time_ext_test.rb

    old new  
    159159    assert_equal DateTime.civil(2005,2,22,15,45),    DateTime.civil(2005,2,22,15,15,10).change(:min => 45) 
    160160  end 
    161161 
    162   def test_plus 
     162  def test_advance 
    163163    assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) 
    164164    assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) 
    165165    assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) 
    166166    assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) 
    167167    assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year 
    168168  end 
     169   
     170  def test_advance_ignores_invalid_options 
     171    assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1, :hour => 3, :min => 4, :sec => 5, :usec => 6, :foo => 19) 
     172  end 
    169173 
    170174  def test_next_week 
    171175    assert_equal DateTime.civil(2005,2,28), DateTime.civil(2005,2,22,15,15,10).next_week 
  • lib/active_support/core_ext/date_time/calculations.rb

    old new  
    3131        # any of these keys: :months, :days, :years. 
    3232        def advance(options) 
    3333          d = to_date.advance(options) 
    34           change(options.merge(:year => d.year, :month => d.month, :day => d.day)
     34          change(:year => d.year, :month => d.month, :day => d.day
    3535        end 
    3636 
    3737        # Returns a new DateTime representing the time a number of seconds ago 
  • lib/active_support/core_ext/time/calculations.rb

    old new  
    7575        # any of these keys: :months, :days, :years. 
    7676        def advance(options) 
    7777          d = to_date.advance(options) 
    78           change(options.merge(:year => d.year, :month => d.month, :day => d.day)
     78          change(:year => d.year, :month => d.month, :day => d.day
    7979        end 
    8080 
    8181        # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension