Devin Asay 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'm not sure why it would fail; that one hour difference is suspiciously like a time zone error or a daylight savings time error (which would still be a bug, if that's what's happening.)

But changing the calculation to use dateitems seems to work okay (and avoids all those inscrutable big numbers):

  put "1/11/08" into tDate
  put "4/15/08" into tStopDate
  convert tStopDate to seconds
  repeat
    convert tDate to dateitems
    add 14 to item 3 of tDate
    convert tDate to seconds
    if tDate > tStopDate then exit repeat
    convert tDate to short date -- if you need that
    put cr & tDate after fld 1 -- or fill your calendar field here
  end repeat

--
Jacqueline Landman Gay         |     [EMAIL PROTECTED]
HyperActive Software           |     http://www.hyperactivesw.com
_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to