Published by Fabian on 03 Jan 2009 at 07:32 pm
Happy new DateTime bugs!
A new year has come to most calendars, and new bugs have come. Normally I expect a date/time related bug on the first day of the new year, but this time a bug was faster! It occurred on 31st of December. Here ist code:
while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } } else { days -= 365; year += 1; } }
Can you spot the bug? You heave heard of where it occurred?
credits and solution
I have an idea for an article about unit testing date and time related code, which I will post on our company blog during next week.
Robert on 04 Jan 2009 at 11:41 am #
I’d call this an infinite loop as soon as you reach day 366, which is Dec-31 in leap years. Nice one though, and certainly a good laugh for Apple