Wangtang Clan http://wangtang.posterous.com stuff from the wangtang clan! posterous.com Thu, 01 Jan 2009 18:01:00 -0800 The Zune Bug http://wangtang.posterous.com/the-zune-bug http://wangtang.posterous.com/the-zune-bug

Here's the offending code for Zune bug that's been causing the mysterious hangs. Can you find it without looking at the solution?


//------------------------------------------------------------------------------
//
// Function: ConvertDays
//
// Local helper function that split total days since Jan 1, ORIGINYEAR into
// year, month and day
//
// Parameters:
//
// Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//------------------------------------------------------------------------------
BOOL ConvertDays(UINT32 days, SYSTEMTIME* lpTime)
{
    int dayofweek, month, year;
    UINT8 *month_tab;

    //Calculate current day of the week
    dayofweek = GetDayOfWeek(days);

    year = ORIGINYEAR;

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


    // Determine whether it is a leap year
    month_tab = (UINT8 *)((IsLeapYear(year))? monthtable_leap : monthtable);

    for (month=0; month< 12; month++)
    {
        if (days < = month_tab[month])
            break;
        days -= month_tab[month];
    }

    month += 1;

    lpTime- >wDay = days;
    lpTime- >wDayOfWeek = dayofweek;
    lpTime- >wMonth = month;
    lpTime- >wYear = year;

    return TRUE;
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/406722/yuan.jpg http://posterous.com/users/10xPjPT3kgF Yuan Wang wangtang Yuan Wang