From: Jeremy McAnally Date: 2008-03-04T05:37:13+09:00 Subject: Re: making a monthly calendar... There's a calendar_helper plugin if this is for a Rails app. Works well for me. --Jeremy On Mon, Mar 3, 2008 at 3:05 AM, Mikkel Bruun wrote: > So I ended up with: > > def calendar_view > firstday = days[0] #all days in month > offset = firstday.wday-1 > boxes =Array.new(5*7) # the viewport > i=0 > #this month from wday of firstday > offset.upto(days.length+offset){boxes[offset+i]=days[i];i=i+1} > i=0 > #pad with previous > 1.upto(offset){boxes[i]=previous.days[-offset+i];i=i+1} > i=0 > #pad with next... > (offset+days.length).upto(boxes.length){boxes[days.length+i+offset]=next_month.days[i];i=i+1} > return boxes > end > > I show this in a rails app using array.groups_of(7) which chops the > boxes array into parts of 7 > > which works ok...untill i hit june 08....where the first week starts > with jun 2nd... > > How are your algorithms working?? > > > -- > Posted via http://www.ruby-forum.com/. > > -- http://jeremymcanally.com/ http://entp.com Read my books: Ruby in Practice (http://manning.com/mcanally/) My free Ruby e-book (http://humblelittlerubybook.com/) Or, my blogs: http://mrneighborly.com http://rubyinpractice.com