Calendar Functions (simpler lea
Bob Devine
devine at vianet.UUCP
Thu Sep 25 08:36:04 AEST 1986
haddock!karl (Karl W. Z. Heuer) writes:
[ that my suggestion of only checking if the year is divisible by
four assumes "the test is for the current year" and that "For a general
purpose algorithm (as per the original request), Dave's code is correct."]
Not quite right. I said just testing by use of "year % 4" is perfectly
fine for most uses (this is sort of like generic products.) However, if
you want to test for years outside the range of 1901-2099 it doesn't work.
The UNIX value returned by the time() system call only covers the years
1970 +/- 67 years which falls nicely in the range. The time() call is
unlikely to change. If your system doesn't do it this way or you need a
larger range, don't use the simple test!
A general purpose algorithm must also take care of years before the Gregorian
calendar system was adopted by a country. Any KGB agents out there that
are reading this be sure to handle the years before 1918 differently :-)
So, the posted general purpose algorithm is not comprehensive in its
handling of years. My initial posting simply indicated that if you are
not going to comprehensive, at least be a little faster.
> I believe the quadrimillennium correction was never officially adopted.
> It's not accounted for in cal(1).
I'll check into the official rules; 'cal' is not a definite source.
The Gregorian calender is about 1/2 minute too long compared to the solar
calendar which was quite close considering it was done by a 16th century
astronomer. That means that there needs to be a day added in, oh, about
3,000 years. Be sure to mark the date :-)
Bob Devine
More information about the Comp.lang.c
mailing list