Saturday, November 4, 2017

Daylight Saving Time: A Coders Achilles' Heel

Good news – tomorrow's a 25 hour day! Most of us get an extra hour of sleep.

It's also a day when date/time bugs are discovered in code. It's an easy mistake for software engineers to make: thinking that there's always 24 hours in a day.

"When is tomorrow?" asks a coder. Well, I'll just add 24 hours to midnight – a common error that I've seen. Adding 24 hours only works if you add it to, say noon, but not midnight. 

When I worked at Wyndham, a business analyst (BA) reported a bug in our hotel booking website. He told us, in our morning meeting, that QA booked a weekend (three nights; arrive Friday and depart Monday). At checkout, the system was reporting only two nights even though the correct Friday – Monday days was displayed. As soon as the BA said it only happened on one weekend, I immediately knew the problem. I said, "See if that weekend coincides with daylight saving time." Sure enough, it did. It made me look smart, but, truth be told, I had not only made this same mistake myself, as a WebObjects developer at Apple, but I had seen this bug deep in the inner workings of WebObjects prior to version 4.5.

It easy to think that every day has 24 hours and it's hard to test for all the edge cases in software.

No comments: