Re: making a monthly calendar...
- From: Todd Benson <caduceass@xxxxxxxxx>
- Date: Mon, 3 Mar 2008 15:42:56 -0500
On Mon, Mar 3, 2008 at 2:14 PM, Mikkel Bruun <mikkel@xxxxxxxxxxx> wrote:
Todd Benson wrote:
> On Mon, Mar 3, 2008 at 1:02 PM, Todd Benson <caduceass@xxxxxxxxx> 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
Yeah, I just realized the edge cases of January and December fail. I
thought the Date object covered that with a -1 or 13 month.
I'm looking into it right now. You might be better off subtracting a
week and adding a week for your big array. For example...
puts Date.new(2008, 1, 5) - 7
=> 2007-12-29
Todd
.
- Follow-Ups:
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- References:
- making a monthly calendar...
- From: Mikkel Bruun
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- From: Mikkel Bruun
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- From: Mikkel Bruun
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- From: Todd Benson
- Re: making a monthly calendar...
- From: Mikkel Bruun
- making a monthly calendar...
- Prev by Date: Re: making a monthly calendar...
- Next by Date: Re: [SOLUTION] [QUIZ] Hello, world? (#158)
- Previous by thread: Re: making a monthly calendar...
- Next by thread: Re: making a monthly calendar...
- Index(es):
Relevant Pages
|