On Fri, 22 Sep 2006, Robert Klemme wrote:

> ara.t.howard / noaa.gov wrote:
>> On Fri, 22 Sep 2006, Patrick Hurley wrote:
>> 
>>> 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.
>> 
>> exactly ;-)
>> 
>> the point is that it always lands into the next month.
>
> Or the month after that - depending on where you start. :-)

sure - but it always starts on the first day of the month:


require 'date'

class Date
   def self.last_day_of_the_month yyyy, mm
     d = new yyyy, mm                        # no day means the first one
     d += 42                                 # always the next month
     new(d.year, d.month) - 1
   end
end

puts Date.last_day_of_the_month(2006, 9)
puts Date.last_day_of_the_month(2006, 12)
puts Date.last_day_of_the_month(2007, 2)

cheers.

-a
-- 
in order to be effective truth must penetrate like an arrow - and that is
likely to hurt. -- wei wu wei