Time#advance and DateTime#advance just got, erm, more betterer in Rails 2.0.

In Rails 1.2.6 and earlier, Time#advance and DateTime#advance only accepted :year, :month and :day options. You'd think :hours, :minutes and :seconds would work too but due to a bug in the code (see ticket #9818), you get something like this instead:

time = Time.utc(2000,10,1,10,30,45)
# => Sun Oct 01 10:30:45 UTC 2000

time.advance(:days =>3, :hour => 2)
# => Wed Oct 04 02:00:00 UTC 2000

Notice how the hour is changed instead of being advanced.

Now, thanks to Geoff Buesing's efforts, passing :hours, :minutes and :seconds options work as you'd expect:

time = Time.local(2005,2,28,15,15,10)
# => Mon Feb 28 15:15:10 0800 2005

time.advance(:hours => 5, :minutes => 20, :seconds => 25)
# => Mon Feb 28 20:35:35 0800 2005

Hell, you can even #advance by :weeks (see ticket #9866):

time = Time.local(2005,2,28,15,15,10)
# => Mon Feb 28 15:15:10 0800 2005

time.advance(:weeks => 2)
# => Mon Mar 14 15:15:10 0800 2005

+1 for consistency and properly behaving code. Thanks to this #advance patch, Geoff was also able to re-use #advance to refactor some other parts of ActiveSupport's time-related extensions.

About the contributor, Geoff Buesing

Geoff Buesing is a regular Rails contributor and I've known him to be the date/datetime/time guru - just look at his submitted patches if you're not convinced. Not too long ago Geoff was given well-deserved commit rights (congrats Geoff)! You won't find him on the Ruby on Rails Core team page yet though - it's probably out of date.

Check out his blog at mad.ly where he writes mostly his adventures with on unobtrusive JavaScript in Rails.