A Computer Bug in JayceLand

I just noticed the other day that the JayceLand Archive was not working right. It would show only the last two weeks (March 20 and March 13) but then stopped and didn't show any until November of last year. I thought it had to do with there being no entries on March 6.

Here's what really happened:

The archive is just a bunch of files named according to the date. To automatically generate the "new" part of the archive, the software makes a note of the most recently published date (i.e. the most recent Thursday before today). It scans through the blog entries in reverse-chronological order and assembles a list of the short descriptions until it gets to an entry that's older than the week it's working on. If there's a file for the Thursday it's on, it displays the link and list of short descriptions as seen in the archive, subtracts 7 days from its marker, and starts accumulating the next list of short descriptions; repeat until there's no more blog entries.

The devil is in the details and, like all annoying computer bugs, it's to do with an incorrect assumption on the part of the programmer (me). When I calculate the most recent Thursday's date, I set the time portion of the day to midnight — dates are represented by the number of seconds since midnight, January 1, 1970. Then, when I need to go back a week, I just subtract 7 * 86,400 (the number of seconds in one day).

Did you get the bug yet?

The incorrect assumption is that all days are 24 hours. There are two that are not: the days when we change in and out of Daylight Saving Time. So March 9 was 23 hours. When my "Thursday" marker passed that Sunday, it was not "Thursday at midnight" but rather "Wednesday at 11 p.m." Since there were no files marked with a Wednesday date, no lines were displayed. At least until it got past November 4, 2007 when we had a 25-hour day and the marker was back to Thursdays again, allowing it to correctly show the entry for November 1, 2007 (when I started the blog).

I gotta say that programming is pretty weird sometimes.

685 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *