Iâ€™ve mentioned before how much I love the vagaries of dates and times in computing, and Iâ€™m glad itâ€™s not a part of my regular day-to-day work or hobby coding.
Hereâ€™s some of the things I expect to happen this year as a result of the leap year:
- Hey, itâ€™s February 29 â€“ some programs, maybe even operating systems, will refuse to recognise the day and think itâ€™s actually March 1. Good luck figuring out how to mesh that with other calendar activities. Or maybe youâ€™ll be particularly unlucky, and the app/OS will break completely.
- But the funâ€™s not over, as every day after February 29, until March 1 NEXT YEAR, youâ€™re a full 366 days ahead of the same date last year. So, did you create a certificate that expires next year, last year? If so, I hope you have a reminder well ahead of time to renew the certificate, because otherwise, your certificate probably expires 365 days ahead, not one year. Or maybe itâ€™ll just create an invalid certificate when you renew one today.
- The same is true for calendar reminders â€“ some reminders for â€śa year aheadâ€ť will be 365 days ahead, not one year. Programmers often canâ€™t tell the difference between AddDays(365) and AddYears(1) â€“ and why would they, when the latter is difficult to define unambiguously (add a year to todayâ€™s date, what do you get? February 28 or March 1?)
- But the funâ€™s not over yet â€“ weâ€™ve still got December 31 to deal with. Whyâ€™s that odd? Normal years have a December 31, so thatâ€™s no problem, right? Uh, yeah, except thatâ€™s day 366. And thatâ€™s been known to cause developers a problem â€“ see what it did to the Zune a few years back.
- Finally, please donâ€™t tell me I have an extra day and ask me what Iâ€™m going to do with it â€“ the day, unless you got a day off, or are paid hourly, belongs to your employer, not to you â€“ they have an extra dayâ€™s work from you this year, without adding to your salary at all.
And then thereâ€™s the ordinary issues with dates that programmers canâ€™t understand â€“ like the fact that there are more than 52 weeks in a year. â€śASSERT(weeknum>0 && weeknum<53);â€ť, anyone? 52 weeks is 364 days, and every year has more days than that. [Pedantic mathematical note â€“ maybe this somewhat offsets the â€śemployerâ€™s extra dayâ€ť item above]
Happy Leap Day â€“ and always remember to test your code in your head as well as in real life, to find its extreme input cases and associated behaviours. Theyâ€™ll get tested anyway, but you donâ€™t want it to be your users who find the bugs.