Thursday, January 01, 2009

Happy New Year for Zune Owners

Here's an exercise for you. What happens when days = 366 in the code below? Maybe the better question is what happens when programmers skip their morning coffee when they reinvent the wheel and write a "simple" date parser with leap year detection? This code was loaded on every 30 GB Zune. Check out the offending module and read the coverage on Engadget. This presents a great case for unit testing!





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



What's in your firmware??