From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,287e8ed2b0c0aabf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-31 03:51:40 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: t_wolf@angelfire.com (Thomas Wolf) Newsgroups: comp.lang.ada Subject: Re: Zeller's Algorithm Date: 31 Jul 2002 03:51:39 -0700 Organization: http://groups.google.com/ Message-ID: <719a5d07.0207310251.8f1adef@posting.google.com> References: <3D3DED1F.24DE3AC8@lmco.com> <3D46CA0E.BCD17D9C@none.provided> <3D470EEE.811F758D@lmco.com> NNTP-Posting-Host: 212.254.0.143 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1028112700 11044 127.0.0.1 (31 Jul 2002 10:51:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 31 Jul 2002 10:51:40 GMT Xref: archiver1.google.com comp.lang.ada:27516 Date: 2002-07-31T10:51:40+00:00 List-Id: Paul A Storm wrote in message news:<3D470EEE.811F758D@lmco.com>... > Rick Maffei wrote: > > > > > While reviewing the latest Risks Digest, I came across the following > > item titled "Possible day-of-week error" concerning the Zeller > > algorithm: > > > > http://catless.ncl.ac.uk/Risks/22.18.html#subj10.1 > > > > Just thought it may be of interest in this thread. > > > > Rick Maffei > > Thanks. That message in the Risks Digest relates to the possibility of the left operand of the final "mod" operation in Zeller's formula becoming negative in some cases. This may be a problem in languages such as C, where e.g. -30 % 7 = -2. In Ada 95, using "mod", this is not a problem, for A mod B is defined to return a modulus in the range 0 .. B-1 for positive B, regardless of the sign of A. If you want to avoid a negative left operand altogether, use the formula Z := (Integer (Day) + (13 * M - 1) / 5 + Y + Y / 4 + Century / 4 + 5 * Century) mod 7; instead of Zeller's Z := (Integer (Day) + (13 * M - 1) / 5 + Y + Y / 4 + Century / 4 - 2 * Century) mod 7; Adding 7 * Century doesn't change the final result (because it's a multiple of 7), but ensures that the left operand is always positive. -- ------------------------------------------------------------------- Thomas Wolf e-mail: t_wolf@angelfire.com