On Feb 1, 2008 6:52 AM, Devin Asay <[EMAIL PROTECTED]> wrote: > I am working on a scheduling program that includes the ability to > schedule an event every other week over a specific time period. To > determine whether the event should occur during any given week during > the time period I do some simple date math to figure out whether a > multiple of 14 days have passed since the first occurrence of the > event. Let's say I've scheduled an event for every other week on > Friday, beginning January 11, 2008 and ending April 11, 2008. For any > given week on my calendar I can calculate whether the event should > show up using this algorithm (pseudocode): > > get the date of the first occurrence of the event and convert it to > seconds > get the date of that the event should fall on if this week falls in > the every-other-week pattern, convert it to seconds > subtract date 2 from date 1 > divide the difference by (60*60*24*14) --the number of seconds in 14 > days > if the difference divides evenly (modulo division = 0) then the event > should occur in the week in question > > This works fine for a few weeks, but then inexplicably fails. For > example, Jan. 11, Jan. 25, Feb. 8, Feb. 22, and March 7 all show the > event properly. But anything after that fails; i.e., March 21, April 4.
I would assume that daylight savings changes for you between March 7 & March 21, so that explains the hours difference. It has long been a source of annoyance to me that "the seconds" is altered to allow for time zones and daylight savings, so that the same number will convert to a different time & date on different systems and depending on the time of year it refers to. Effectively, this means that you cannot really use "the seconds" for such date & time operations. How about this sort of thing (again in pseudo code): get the date of the first event convert it to dateItems add 14 to item 3 convert back to date (which will work even if you have something that looks weird in date items e.g. 2008,3,42,....) Cheers, Sarah _______________________________________________ use-revolution mailing list [email protected] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
