ara.t.howard / noaa.gov wrote:

>   irb(main):005:0> months[months.index(current), 42].size
>   => 24
>
> not good if the app is a mortage calculator!  ;-)

Sorry if this response is too late to be useful to anyone, but here's a 
solution that surprised me with its elegance.  I read the OP and 
immediately thought, "Oh, just spin forward 86,400 (seconds per day) 
until the month changes" and, of course, someone had already posted this 
reply.  However, I wrote some code as a youth that played with dates 
using division and moduli, and this post got me reminiscing on that.  
Here's a resurrected version.  I was very pleased to discover it handles 
negative numbers, which made writing Time#prev_month trivial and elegant.

class Time
  def next_month n=1
    t = Time::mktime year + Integer(n)/12, ((month+n-1)%12)+1
    t.strftime "%B"
  end

  def prev_month n=1
    next_month -n
  end
end

Cheers, and thanks for asking an interesting question!

-dB

-- 
David Brady
ruby_talk / shinybit.com
C++ Guru. Ruby nuby.  Apply salt as needed.