Skip to main content

Invalid date

Datetime calculations are one of the hardest things to get right in software development. Even though there are (somewhat) clear rules how the time works there are still a lot of variations that can cause all sorts of issues.

I would have imagined a leap day would be one of the easiest exceptions to handle. After all it's quite simple to calculate those days. It's also not like those famous oversights made with storing the time like only storing the last two digits of the year which led to the infamous Y2K mayhem or the upcoming Y2K38 (when the Unix epoch resets back to 1st of January 1970).

Today I have read about at least two issues caused by the leap day. First one was some gas pump payment system that caused those pumps not working at all. The second one the classic "fail on any error" where the Chinese marriage certificate system claimed everybody too young to get married because comparison between their birthday and a date exactly 22 years ago failed due the later being an invalid date.

Four years isn't exactly as long time not to think the software isn't used anymore after that time. Not like the unix epoch which nobody thought would still be used 68 years later!