• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Can someone explain the Zune timing system to me?

Shadow Conception

Golden Member
If you haven't heard, all Zune 30s were affected by a freeze today. Now apparently, the problem's been isolated.

The code's as follows (better-syntaxed representation is in the link):

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

So, the main loop only executes if days are greater than 365. Well, in a typical non-leap year, there are only 365 days, which means that this loop only executes when it's a leap year (366 days). Is this correct?

Additionally, the first if statement only executes if days are greater than 366. In what scenario would days ever be greater than 366? We don't have double leap years, do we? Does this mean that if statement never executes as well?

I'm really confused, maybe I'm just getting it all wrong. Can someone explain this to me?
 
Not quite. The example doesn't show days being set, but from the semantics days must be set to the total number of elapsed days since the start of the "origin year" of 1980.

There are two variables that control the loop:

int days;
int year;

It starts with year == 1980, and days == x where x is the total number of days from some start date in 1980 (say, 1/1) through to the current day.

The loop runs as follows in pseudocode:

while days greater than 365
if year is a leap year
->subtract 366 from days
-> add 1 to year
else
->subtract 365 from days
-> add 1 to year

Then there would be a part that they don't show after the loop:

convert days to month/day

The result would be month/day/year for the current day, except as has been discovered, the loop breaks on the last day of a leap year.

 
The time is stored as a long representing seconds since 1/1/80. You divide that number by 86400 to get the number of days since that date. Then you start subtracting 365 or 366 from that number until you've got less then 365 days, then you do the same with months and so on.
 
Back
Top