Unfortunately, a day isn't always 24 hours

You may have noticed that the calendar in the sidebar on the right uses a nifty javascript/AJAX implementation so the page doesn't need to refresh when you go backward or forward. Yesterday I discovered a really stupid bug in it: go backward a month, then go forward to October again (unless it's already after October when you read this, in which case you just need to go back, assuming I haven't fixed the bug already). You'll see October 29th appears twice, and the days after it are shifted ahead.

How does this happen? It's because the javascript Date object doesn't have any built-in support for date arithmetic; you can't easily add a day to it for instance. So I built my own support for that. Since you can convert a date to and from a representation in seconds, to advance one day I simply add the number of seconds there's in a single day to the date object. Which worked great, until now.

You see, I'd been working under the premise that dates are all 24 hours long, not an unreasonable assumption you might think. Unfortunately, thanks to the end of Daylight Saving Time, October 29th is 25 hours long, throwing off my algorithm.

I'm going to fix this, of course. Soon, I hope.

UPDATE: It appears I'm an idiot, and the Date object does support the type of arithmetic I need. I don't see how I missed that when I implemented it... Anyway this'll make fixing it a lot easier. I still need to actually do it, of course. :)

Update 2006-10-31: The bug has been fixed. All seems well with the calendar now.

Categories: Site news
Posted on: 2006-10-30 15:22 UTC.

Comments

No comments here...

Add comment

Comments are closed for this post. Sorry.

Latest posts

Categories

Archive

Syndication

RSS Subscribe