Re: making a monthly calendar...



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

.



Relevant Pages

  • Re: pleeeaaaasssseeee someone tell me...
    ... "pleasure wheeler" bike ride group not a speeding biking group and if he ... our cat is breaking all our window screens so she can party outside ... oh Yeah with all this I didn't kill anyone and I didn't smoke. ... I will not fail. ...
    (alt.support.stop-smoking)
  • Re: The rewards of whistle - blowing
    ... your mouth empty, where's your manners! ... One lone nutter it is then. ... Yeah, yeah, the lurkers support you in email. ... control what people say and think are doomed to fail, ...
    (uk.business.agriculture)
  • Re: Awfully quiet in here lately...
    ... However, they still fail with ... PBRAIN.C by Daniel B. Cristofani ... side-effects of the array, such as array wrap-around, etc. ... expanding to a small set of basic instructions. ...
    (comp.lang.misc)
  • Re: Ill show you mine...
    ... We just have to stick together like glue. ... 250 cigarettes not smoked, saved $102.64 to pay for her Vii. ... I will not fail. ... So yeah, I guess that makes Wed the 23rd a month officially huh? ...
    (alt.support.stop-smoking)