Brian Donovan has a great writeup of his new Duration fix to the Rails’ Time convenience methods that, until now, have been slightly broken.
Here’s the summary. Before (bad):
1 2 3 4 |
Time.now #=> Thu Jan 25 21:01:31 -0800 2007 1.month.from_now #=> Sat Feb 24 21:01:34 -0800 2007 |
Oops – apparently one month only equals 30 days, not really one month. But now, in edge:
1 2 3 4 |
Time.now #=> Thu Jan 25 21:01:31 -0800 2007 1.month.from_now #=> Sun Feb 25 21:01:34 -0800 2007 |
And check out this little inspect goodie:
1 2 |
>> 3.weeks #=> 21 days |
And just so you’re not mislead by this post’s title, this fix applies to all the time helpers, not just month.from_now. Read the full rundown to become fully enlightened.
tags: rubyonrails, rails
