News for hackers. Stuff that matters.
Re:Source code of the file with the Zune bug (starts on line... by tlrobinson on Thursday January 01, 2009 @10:25PM (#416987)
Making that ">=" would make that entire "if" check redundant, since we already know it's at least 365 (because of the "while" condition)

I think the "while" condition should actually be

    while ((days > 365 && !IsLeapYear(year)) || (days > 366 && IsLeapYear(year)))
(or perhaps some simplification that I'm too lazy to figure out right now)

And then the inner "if" condition can be eliminated. Thus the final code could be:

    while ((days > 365 && !IsLeapYear(year)) || (days > 366 && IsLeapYear(year)))
    {
        if (IsLeapYear(year))
            days -= 366;
        else
            days -= 365;
        year += 1;
    }
This seems logical and easier to understand than the original too.

Edit: if you want to get ternary-operator fancy:

    while (days > (IsLeapYear(year) ? 366 : 365))
    {
        days -= IsLeapYear(year) ? 366 : 365;
        year += 1;
    }
Re:Source code of the file with the Zune bug (starts on line... by judofyr on Friday January 02, 2009 @09:48AM (#417343)
Let's be a little more DRYer:

    days_in_year = IsLeapYear(year) ? 366 : 365;
    while (days > days_in_year) {
        days -= days_in_year;
        year += 1;
    }
Re:Source code of the file with the Zune bug (starts on line... by blablebla on Friday January 02, 2009 @10:25AM (#417363)
How about a little more CORRECTer?

#define diy(y) (IsLeapYear(y) ? 366 : 355)

while (days > diy(year)) { days -= diy(year); year += 1; }

Re:Source code of the file with the Zune bug (starts on line... by ars on Friday January 02, 2009 @10:39AM (#417370)
For the confused: the year changes each time, so you need to recheck IsLeapYear each time.

But I wouldn't do it with a define but rather:

while (days > (days_in_year = IsLeapYear(year) ? 366 : 365)) { days -= days_in_year; year += 1; }

Re:Source code of the file with the Zune bug (starts on line... by tlrobinson on Friday January 02, 2009 @12:35PM (#417470)
Incorrect, since you don't update days_in_year on each loop iteration. If you really want...

    while (days > (days_in_year = IsLeapYear(year) ? 366 : 365)) {
        days -= days_in_year;
        year += 1;
    }
Re:Source code of the file with the Zune bug (starts on line... by jabr on Friday January 02, 2009 @12:10PM (#417444)
I prefer:

  for (;;) {
    int days_in_year = IsLeapYear(year) ? 366 : 365;
    if (days <= days_in_year) break;
    days -= days_in_year;
    year += 1;
  }