Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!rutgers!sri-spam!sri-unix!hplabs!hao!nbires!vianet!devine From: devine@vianet.UUCP (Bob Devine) Newsgroups: net.lang.c Subject: calculating leap years Message-ID: <40@vianet.UUCP> Date: Mon, 6-Oct-86 22:00:34 EDT Article-I.D.: vianet.40 Posted: Mon Oct 6 22:00:34 1986 Date-Received: Wed, 8-Oct-86 01:03:18 EDT Reply-To: devine@vianet (Bob Devine) Organization: ViaNetix, Inc., Boulder, CO Lines: 44 First I need to correct myself. I wrote that a test for divisiblity of the year by 4000 should be used accommodate the difference between the Gregorian calendar and the true tropical year. Wrong. There is currently not a leap year correction accepted beyond the 400-year rule even though a straight line extrapolation for the Gregorian minus the tropical year leads to an extra leap day in about 3000 years. At the level of difference (365.2425 - (approx.)365.2422), there is too much "noise" caused by the varying earth rotation. Thanks to Henry Spencer for making me double check. That doesn't mean it wouldn't be better to use the rule of tossing out one leap year every 128 years (=365.24219) instead of three every four hundred years.... In reply to fgd3@jc3b21.UUCP (Fabbian G. Dufoe) who writes: > It is particularly galling to see a correct algorithm criticized as > overkill when it is as simple and short as the above code segment. There > may be a justification for writing code that only works part of the time if > the fix is costly and difficult. However, it should be a general rule that > an algorithm which works in all cases is preferred over one that only works > in most cases. > Instead of panning someone's code because he has written it more correctly, > one should adopt the improved algorithm with gratitude. You are missing the point: I wrote that doing the simple check for divisibility by four is sufficient for most programs. I would bet that 99% of programs don't need to handle dates with precision outside of +/-20 years from the current date. Geneology programs might want more. Astronomical programs almost certainly do. In the same sense, not all arithmetic calculations need be done in double precision. That algorithm for the Gregorian leap years DOES NOT work in all cases. It does only after a country has adopted that calendar. Japan, for instance, didn't adopt it until 1873. USSR did so in 1918. [I wonder if that means its "October Revolution" really falls in the Gregorian November because of the 13 days its calendar 'lost'? I'll check.] I'll post to mod.sources a program to correctly handle leap years for a large range of years. It will handle the problem of different countries switching calendars (somewhat). Expect it in a coupl'a weeks. Bob Devine