Top «Prev(2008-12-31) Latest Next(2009-01-05)» Edit

pterjan's diary


2009-01-03

  Zune

The now famous bug of Zune not booting this year on December 31 has been identified.

    while (days > 365)
    {
        if (IsLeapYear(year))
        {
            if (days > 366)
            {
                days -= 366;
                year += 1;
            }
        }
        else
        {
            days -= 365;
            year += 1;
        }
    }

As you can see, when day > 365 but <= 366, so on the last day of a leap year, it will loop forever. It's basically because the while loops thinks that every year is 365 days long. The optimal way to compute it would be with a division but it needs to think about it before writing ( :) ) so I would write it like the following to not duplicate the length of a year (or better, create a function NbDays(year)):

nbDays = IsLeapYear(year) ? 366 : 365;
while (days > nbDays)
{
    days -= nbDays;
    year += 1;
    nbDays = IsLeapYear(year) ? 366 : 365;
}
Today's TSUKKOMI(Total: 1) [Add a TSUKKOMI]
  Thomas (2009-01-06 16:49)

Sigh, good thing we got time stamps :)


2004|06|07|08|09|11|
2005|01|02|05|06|07|08|09|10|11|12|
2006|01|02|03|06|08|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|12|
2011|02|04|06|
2012|01|05|11|
2013|01|02|04|06|
2014|02|
2015|06|
2017|05|07|12|