# new date conversion bug?

Devin Asay devin_asay at byu.edu
Thu Jan 31 17:02:07 EST 2008

```On Jan 31, 2008, at 2:33 PM, Sarah Reichelt wrote:

> On Feb 1, 2008 6:52 AM, Devin Asay <devin_asay at byu.edu> 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.

AAAARRRGH! Of course, I'd completely forgotten that the daylight
savings time change was moved up to March! At first I was wondering
if it had something to do with the leap year, but that wouldn't have
explained why March 7th was okay.

Thanks Stephen, Sarah, Jacque and Colin for your responses and
suggestions. I can fix it now.

I love this list!

Devin

Devin Asay
Humanities Technology and Research Support Center
Brigham Young University

```