From: Todd Benson Date: 2008-03-01T16:51:40+09:00 Subject: Re: making a monthly calendar... On Fri, Feb 29, 2008 at 4:30 PM, Mikkel Bruun wrote: > Hey > > I trying to do a calendar based app.. > > So i have a monthly view with 5 weeks of 7 days = 35 boxes... > > Just like google calendar i need to show the selected month, and fill in > the blanks with the previous and next months days... > > so february is ending today on a friday. So in the last 2 boxes of the > 5. week i need to show march 1 and 2 and the same in the front... > > I have this Month class. Which contains all the dates for a given month, > as well as references to the next and previous months.... > > there must be some kind of pattern im not getting bevause i keep > slamming my head against the wall on this.... > > anyone who have a quuck solution??? > > thanks!! > > mikkel Here's one for fun. I'm pretty sure you don't want to use this (for all I know, you might be laughed out of the room :), but it demonstrates some methods... require 'enumerator' o = (t = Date.today).wday c = (-1..1).inject([]) {|a, i| a << (t.month + i)}.map {|i| 1..Date.new( t.year, i, -1 ).day}.map {|i| i.to_a} o.times {c[1].unshift c[0].pop} c[1..2].flatten.slice(0..35).compact.each_slice(7) {|i| p i} You'd have to tidy up the output of course (using #join or whatever). Also, as you can see, 5 weeks doesn't necessarily cover a month. In March's calendar for 2008, there are 6 days out of February. Todd