Patrick Hurley
9/21/2006 8:20:00 PM
On 9/21/06, James Moore <banshee@banshee.com> wrote:
> > d += 42 # warp into the next month
>
> You need to add a month, not a fixed number of days, since you can't predict
> how many days are in the next month:
>
> irb(main):033:0> d = Date.new 2006, 1, 31
> => #<Date: 4907533/2,0,2299161>
> irb(main):034:0> (d >> 1).to_s
> => "2006-02-28"
>
>
> irb(main):039:0> d = Date.new 1996, 1, 31
> => #<Date: 4900227/2,0,2299161>
> irb(main):040:0> (d >> 1).to_s
> => "1996-02-29"
>
> - James Moore
>
>
>
Yeah that was my first thought too, but notice he is constructing a
new date at the beginning of the month. I am guessing he picked 42,
over 32 as it is just much better number.
pth