From: Mikkel Bruun Date: 2008-03-04T05:14:11+09:00 Subject: Re: making a monthly calendar... Todd Benson wrote: > On Mon, Mar 3, 2008 at 1:02 PM, Todd Benson wrote: >> > offset.upto(days.length+offset){boxes[offset+i]=days[i];i=i+1} >> > boxes array into parts of 7 >> with the correct number of days in each, centered around the current >> display, but, obviously, you won't have to do that, because you have >> >> today = Date.today #use whatever date you want >> >> offset = Date.new(today.year, today.month, 1).wday >> # ^^^^^^ that was the line I screwed up at first >> months_of_concern = (-1..1).inject([]) {|a, i| a << (today.month + i)} >> >> month_ranges = months_of_concern.map {|month| 1..Date.new( today.year, >> month, -1 ).day} > > That's one line and suppose to be today.month following today.year. > >> day_sets = month_ranges.map {|i| i.map} >> >> offset.times {day_sets[1].unshift day_sets[0].pop} >> p day_sets[1..2].flatten.slice(0..42) >> > > Todd thanks for all your help but your code seems to break when changing years. showing january 2008 breaks when populating decemeber 2007 etc... i believe this line has to take this into account: month_ranges = months_of_concern.map {|month| 1..Date.new( today.year, month, -1 ).day} Mikkel -- Posted via http://www.ruby-forum.com/.