||[Jan. 2nd, 2009|07:52 am]
Zunes across the country freeze due to leap year bug|
I'd be laughing if I didn't have a suspicion that the same thing happened to my team on Wednesday. Sigh.
I'm glad I switched to iPod. My cousin Danny is totally lauging right now.
Also? I'm considering converting to Mac...
From what I understand, they're working now. They just stopped working for the 366th day of the year, resuming on the 1st of the next.
So, it turns out that Microsoft had released the source code
for the RTC they implemented on the Zune. It has this in it:
year = ORIGINYEAR; /* = 1980 */
while (days > 365)
if (days > 366)
days -= 366;
year += 1;
days -= 365;
year += 1;
I'm not a programmer, but it looks to me that the code you posted says:
When the count is 366 days or more, subtract 365, unless it is a leap year. In that case, subtract 366 days, but not until the count reaches 367 or more.
Looks correct to me. Is there something I'm missing?
If they wanted "366 days or more", they should have put ">= 366" - "greater than or equal to 366". Instead they just had "greater than 366".
2009-01-02 10:21 pm (UTC)
Re: What is the mistake?
So, here's what's going on.
First, say you're on the first day of 1981.
days is going to be least 367. This code is going to see that since
year is currently set to 1980, which is a leap year, and we have more than 366 days, we should subtract that number of days and then add one to
year. That leaves one day remaining, which is used to get the date.
However, let's say that we're on the last day of 1984 instead. This code is going to run through until we eventually have a
year of 1984 and a
days of 366. Now, we're still in the loop, since
days is still more than 365, so we hit the if statement. It is a leap year, so we go into that first if statement. It's the next one that's the problem. It's looking for a situation where
days is more than 366, but it's currently exactly equal to 366, so we don't run the code inside of it and we still have 366 left in
days. Since we matched the condition on the outer if statement, the code in the else statement is ignored and we reach the end of the while loop, which then checks to see whether
days is still more than 365, which it is, so it runs the loop again. Since it never actually getting
days below 365, it's essentially an infinite loop.
Heh... some AJAX code on the Apollo site go awry or something?
HAM, actually. Bug in the scheduled-execution forecasting code. Grar.
My personal opinion is that it was caused by the weather. Probably the same "Threat of snowfall paralyzes Seattle" phenomenon. It certainly has nothing to do with the quality of products or the lack of comprehensive test plans, or the fact that we've never seen our clocks lock up our computers in a leap year. The weather. Definitely the weather.