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 233 233 assert_equal Time.utc(2005,2,22,15,45), Time.utc(2005,2,22,15,15,10).change(:min => 45) 234 234 end 235 235 236 def test_ plus236 def test_advance 237 237 assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1) 238 238 assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) 239 239 assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) … … 241 241 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 242 242 end 243 243 244 def test_utc_ plus244 def test_utc_advance 245 245 assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) 246 246 assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) 247 247 assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) 248 248 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) 249 249 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 250 250 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 251 255 252 256 def test_next_week 253 257 with_timezone 'US/Eastern' do -
test/core_ext/date_time_ext_test.rb
old new 159 159 assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(:min => 45) 160 160 end 161 161 162 def test_ plus162 def test_advance 163 163 assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) 164 164 assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) 165 165 assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) 166 166 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) 167 167 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 168 168 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 169 173 170 174 def test_next_week 171 175 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 31 31 # any of these keys: :months, :days, :years. 32 32 def advance(options) 33 33 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) 35 35 end 36 36 37 37 # Returns a new DateTime representing the time a number of seconds ago -
lib/active_support/core_ext/time/calculations.rb
old new 75 75 # any of these keys: :months, :days, :years. 76 76 def advance(options) 77 77 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) 79 79 end 80 80 81 81 # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension