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.