?

Log in

No account? Create an account
Zunes across the country freeze due to leap year bug I'd be… - Chronicles of a Hereditary Geek [entries|archive|friends|userinfo]
Darth Paradox

[ website | Pyrlogos - a fantasy webcomic ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Jan. 2nd, 2009|07:52 am]
Darth Paradox
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.
linkReply

Comments:
[User Picture]From: kinkyprude
2009-01-02 06:11 pm (UTC)
Oh Noes!
I'm glad I switched to iPod. My cousin Danny is totally lauging right now.
Also? I'm considering converting to Mac...
(Reply) (Thread)
[User Picture]From: iris_of_ether
2009-01-02 07:45 pm (UTC)
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.
(Reply) (Parent) (Thread)
[User Picture]From: kreeblah
2009-01-02 09:11 pm (UTC)
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 (IsLeapYear(year))
    {
        if (days > 366)
        {
            days -= 366;
            year += 1;
        }
    }
    else
    {
        days -= 365;
        year += 1;
    }
}


Oops.
(Reply) (Thread)
[User Picture]From: wannabepoet18
2009-01-02 09:54 pm (UTC)

What is the mistake?

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?
(Reply) (Parent) (Thread)
[User Picture]From: darthparadox
2009-01-02 10:12 pm (UTC)

Re: What is the mistake?

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".
(Reply) (Parent) (Thread)
[User Picture]From: kreeblah
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.
(Reply) (Parent) (Thread)
From: yts88
2009-01-03 01:14 am (UTC)
...it almost was.
(Reply) (Thread)
From: dacut
2009-01-03 01:30 am (UTC)
Heh... some AJAX code on the Apollo site go awry or something?
(Reply) (Thread)
[User Picture]From: darthparadox
2009-01-03 01:47 am (UTC)
HAM, actually. Bug in the scheduled-execution forecasting code. Grar.
(Reply) (Parent) (Thread)
[User Picture]From: wayzgoose
2009-01-03 06:03 pm (UTC)
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.
(Reply) (Thread)