Yet another DST-switchover gotcha

2006-04-09 01:21:00

Wow, can't believe it's been a month and a half since I posted last. It's pretty much been the final big push to get the chapter content for the book all wrapped up.

Last week provided Bug Entertainment for the Whole Family again as we switched to daylight savings time. I had it in the back of my head that there might be some weird bugs surface in Scooby, and I was right -- and just like the last time, it was something very weird and specific. This time, you couldn't edit all-day events to start on Sunday, April 1st. They'd all jump right over to sit on Monday.

I'll even cop to the fact that it took me a good ten minutes or so to snap to the fact that it was a DST-switchover bug.

The bug was in the Date.diff method in date.js., comparing by single days. It was doing parseInt of the result -- so in the case of that Sunday, the result of 23/24 was 0.9583333 ... and it would get truncated to zero. The obvious solution (once you know that little gopher hole is there) is to round the result -- an annoying bit of math to have to do every time for a case that happens once a year.

I keep thinking there ought to be a less annoying way to fix that.


This is the blog for Matthew Eernisse. I currently work at Yammer as a developer, working mostly with JavaScript. All opinions expressed here are my own, not my employer's.


Previous posts

All previous posts ยป

This blog is a GeddyJS application.