Feed on
Posts
Comments

Second Tuesday Woes

Last month the BOT that sends out the White Box Drill reminders got it spectacularly wrong on January 8th and 15th. This was perhaps caused by an anomaly in Microsoft’s Task Scheduler. I haven’t made the vast time investment to verify this theory, but the schedule setup clearly states ‘second and fourth Tuesday’, and has been working correctly for several months.

No longer trusting the scheduler, I decided to move the process to my always-on Sheeva-Plug Linux box. To my knowledge, the Linux CRON doesn’t support the second-Tuesday idea so I decided to try to write a routine to tell whether any given Tuesday was a second or fourth one. Simple, right? just take the integer part of the day of the month divided by seven and you have it. No, it’s not quite that simple.

I boiled it down to a single excel statement which I think works. I’ve set it down in pseudo-code below. I checked this algorithm for several months in 2012 and 2013 and found no errors. Is it really correct? I don’t know.

Question #1: Can anybody figure out how to make a general test of its correctness (short of exhaustion)?

Question #2: Does this cover all cases? I’d be happy if somebody came up with a falsification.

———————————————–

DOM    # day of month
DIM    # count of this day in month e.g. 2 is second example of whatever day of the week it is. e.g. second Wednesday

DIM = Integer part of ( DOM / 7 ) + (IF (DOM modulo 7 == 0) true:0; false:1)

In Excel format:DIM = INT(DOM/7)+(IF(MOD(DOM,7)=0,0,1))

3 Responses to “Second Tuesday Woes”

  1. Ed Kelm, KD7TUN says:

    Peter:

    Simply put, you want day 1 thru 7 of the month to return a “1”, day 8 thru 14 a “2”, etc. I think your algorithm does that if your pseudo code translates to “if DOM mod 7 is not 0, add 1 to the result of the integer divide, otherwise, don’t.” The reason for the complexity is that DOM is 1 based, not zero based. The following single line will also work, and might be considered simpler: (written in BASIC-like code)

    DIM = 1+ (DOM-1)\7 (“\” is integer divide)

    Tested both ways in QB 4.0 for DOM from 1 to 31 – both work fine.
    Ed K.

  2. Dave V K9MRQ says:

    More simply, if the date is between 8 and 14, it is the second Tuesday. If the date is between 22 and 28, it is the fourth Tuesday.

    Dave

  3. cpal says:

    Might check this out if your interested in using cron:

    http://stackoverflow.com/questions/11683387/cron-run-every-2nd-and-4th-saturday-of-the-month

    Could probably be adapted for what you are trying to do.

    c

Leave a Reply