On Fri, 22 Sep 2006, Paul L. wrote:
Hard: construct a date for the first day of the target month, then add days
unitil the month number changes. Then go back one.
I think I know which option you’ll choose.
except you have to handle december specially - else you’ll end up with
with the wrong year.
easiest is probably:
harp:~ > cat a.rb
def self.last_day_of_the_month yyyy, mm
d = new yyyy, mm
d += 42 # warp into the next month
new(d.year, d.month) - 1 # back off one day from first of that
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)
harp:~ > ruby a.rb