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;
}