Sunday, July 13, 2008

Project Calendar - Calendar Rows

I don't have a computer, but it doesn't stop me from thinking.

Something I hadn't done in my prototypes was to have a dynamic number of rows (calendar Weeks) depending on the number of days. When I was developing the prototypes, I tried to come up with a logic for this but couldn't find it. I wasn't in that "mode", I guess.

For some reason, while playing [PS2] Ratchet: Deadlocked, it hit me. You know when something is too simple or easy that it becomes hard? Well, this is one of those instances.

calendarWeeks = rows in the calendar.

calendarWeeks ← ceil((daysInMonth + offset) / 7) - 1

I'm using "ceiling" and "-1" to be as logical as possible, without logical-shortcuts. If you think about it, let's say you have 31 days in a certain month + an offset of 1, devided by 7. You end up with 4.5714. You can't have half of a row, so you end up with 5 rows, which works. But, in my algorithm, the Rows loop starts at 0 for the calculation of currentDay, therefore the logic behind "-1" (from 0 to 4 is 5 rows).