Friday, April 4, 2008

Project Calendar - currentDay With Offset

Two Project Calendar updates in one day. I'm on a roll!

While eating dinner, I was just messing around in my composition book, playing with the First-Day of Month Offset. When the first day of the month is on a Sunday, the offset is 0, when the first day of the month is on a Monday, the offset is 1, and so on.

I played around with just Offset 1 with a calendar I drew in my book.

Calendar-Table
Note: I'm not currently trying to figure out how to get the offset with knowing the month and year. I know there are different ways to logically come up with an offset number, but that will come much later.

If I take the 18th, it's on the fifth column on the third row (indexed 2). With very simple logic added to my original equation, I get this:

currentDay ← (columnIndex - offset) + (rowIndex * 7)

For the 18th, that's (5 - 1) + (2 * 7). That works. Let's validate it...

It seems to work well for an offset of 1, how about another offset? Let's say the week starts on Friday? Friday would be an offset of 5. Let's use the equation on three dates to validate the statement:

Calendar-Table
5 ← (3 - 5) + (1 * 7)      //(-2 + 7)
18 ← (2 - 5) + (3 * 7)    //(-3 + 21)
21 ← (5 - 5) + (3 * 7)    //(0 + 21)

I thought it was going to take me a lot longer to figure out, or validate, an equation that works with any offset. I probably won't update the Pseudocode before next week. I feel that if I see any more logic, code, or HTML that my head is going to explode. I'm going to take it easy for the rest of the weekend.