[fpc-pascal]Week Day

Gabor DEAK JAHN djg at tramontana.co.hu
Fri Apr 20 05:19:51 CEST 2001


At 4/19/01 08:44 AM, you wrote:

Jim,

 > One question; does it properly handle leap years? Is that what the "if M >
 > 2 then Y1..." line is for?

Both lines contribute to this in their own way. The second line (WeekDay :=
...) accounts for the different length of the leap years, the first line
makes the algorithm avoid the problems of post-February months (as the extra
day is in the middle of the year, calculating pre-Feb 28 days should ignore
the current leap year while post-Feb 29 dates should take it into
consideration). The algorithm shifts the first two months as if they were
the last months of the previous year, thereby shifting the extra day to the
end of the year, eliminating the need to handle it individually.

The algorithm is a modification of the ingenious formula invented by a
mathematician named Zeller, way before the era of computers (some time in
the 19th century, if I remember correctly). He used an even nicer formula,
at least nicer for a mathematician, without a table lookup for the various
months (with an extra addition and a division), but the actual
implementation is certainly faster with a lookup.


Bye,
   Gábor

-------------------------------------------------------------------
Gabor DEAK JAHN -- Budapest, Hungary.
E-mail: djg at tramontana.co.hu, djg at argus.vki.bke.hu





More information about the fpc-pascal mailing list