T
Tor Rustad
Richard Heathfield wrote:
[Q: To leap or not to leap?]
The Gregorian Calendar is not used everywhere in the world, even in the
Catholic countries, it was not used before
assert(year > 1582);
The Protestantic countries was far more skeptical, and didn't like to be
dictated by the Pope. Anyway, Germany, Switzerland and Denmark-Norway
finally followed in
assert(year > 1700);
As usual, the Brits was slow (btw they might switch to euro some day!),
so for the British Empire we have
assert(year > 1752);
at least you beat Sweden/Finland to it by a year. ;-) However, the
Swedes did this their own way, and instead of loosing many days at once,
they dropped 10+ leap years afterwards.
etc. etc.
As an example to us all, in 1983, Stanley Rabinowitz made this
*masterpiece* of a maintainer response to a VAX/VMS leap-year bug report:
http://rudy.ca/lycomplaint.html
[Q: To leap or not to leap?]
Here's a better method:
int really_is_leap(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
This one has the merit of actually giving the right results.
The Gregorian Calendar is not used everywhere in the world, even in the
Catholic countries, it was not used before
assert(year > 1582);
The Protestantic countries was far more skeptical, and didn't like to be
dictated by the Pope. Anyway, Germany, Switzerland and Denmark-Norway
finally followed in
assert(year > 1700);
As usual, the Brits was slow (btw they might switch to euro some day!),
so for the British Empire we have
assert(year > 1752);
at least you beat Sweden/Finland to it by a year. ;-) However, the
Swedes did this their own way, and instead of loosing many days at once,
they dropped 10+ leap years afterwards.
etc. etc.
Test your function, and see how it works on years that you know to be leap
years (eg 1976, 2000, 2004, 2008) and years you know not to be leap years
(2001, 2002, 2003, 2005).
Then switch to a working algorithm.
As an example to us all, in 1983, Stanley Rabinowitz made this
*masterpiece* of a maintainer response to a VAX/VMS leap-year bug report:
http://rudy.ca/lycomplaint.html