Am Dienstag, den 17.01.2006, 07:06 +0900 schrieb ara.t.howard / noaa.gov:
> On Tue, 17 Jan 2006, Detlef Reichl wrote:
> 
> > Try this:
> >
> > irb(main):040:0* t = Time.now
> > => Mon Jan 16 21:27:58 CET 2006
> > irb(main):041:0> m = t.mon
> > => 1
> > irb(main):042:0> nt = Time.mktime 2006, m + 1
> > => Wed Feb 01 00:00:00 CET 2006
> > irb(main):043:0> p nt.strftime("%B")
> > "February"
> > => nil
> > irb(main):044:0> nt = Time.mktime 2006, m + 2
> > => Wed Mar 01 00:00:00 CET 2006
> > irb(main):045:0> p nt.strftime("%B")
> > "March"
> > => nil
> 
> but
> 
>    harp:~ > ruby -e'  p(Time::mktime(2006,13))  '
>    -e:1:in `mktime': argument out of range (ArgumentError)
>            from -e:1
> 
> 
OK

: p(Time::mktime(2006,(13%12)))
Sun Jan 01 00:00:00 CET 2006


> i prefer the stupid approach:
> 
>      harp:~ > cat a.rb
>      class Time
>        def this_month
>          strftime '%b'
>        end
>        def next_month n = 1
>          t = dup
>          s = 60 * 60 * 24
>          n.times{ m = t.month; t += s until t.month != m }

Outch :-) found no good logic? who cares, lets do it with brute force

>          t.strftime '%b'
>        end
>      end
> 
>      t = Time::mktime 2006, 12
>      p t.this_month
>      p t.next_month
>      p t.next_month(2)
> 
> 
>      harp:~ > ruby a.rb
>      "Dec"
>      "Jan"
>      "Feb"
> 
> 
> regards.
> 
> -a