From: t_wolf@angelfire.com (Thomas Wolf)
Subject: Re: Zeller's Algorithm
Date: 31 Jul 2002 03:51:39 -0700
Date: 2002-07-31T10:51:40+00:00 [thread overview]
Message-ID: <719a5d07.0207310251.8f1adef@posting.google.com> (raw)
In-Reply-To: 3D470EEE.811F758D@lmco.com
Paul A Storm <paul.a.storm@lmco.com> 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
next prev parent reply other threads:[~2002-07-31 10:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-23 23:56 Zeller's Algorithm Paul A Storm
2002-07-24 7:59 ` Thomas Wolf
2002-07-24 21:30 ` Paul A Storm
2002-07-29 8:29 ` Thomas Wolf
2002-07-30 4:35 ` Robert Dewar
2002-07-30 8:20 ` Thomas Wolf
2002-07-30 17:17 ` Rick Maffei
2002-07-30 22:10 ` Paul A Storm
2002-07-31 10:51 ` Thomas Wolf [this message]
2002-07-31 14:33 ` Frank J. Lhota
2002-07-31 19:13 ` Robert A Duff
2002-07-31 19:26 ` Darren New
2002-07-31 20:01 ` Hyman Rosen
2002-07-31 20:15 ` Frank J. Lhota
2002-07-31 21:08 ` Robert A Duff
2002-07-31 22:34 ` Hyman Rosen
2002-07-31 22:57 ` Robert A Duff
2002-08-01 15:17 ` Hyman Rosen
2002-08-01 16:41 ` Frank J. Lhota
2002-07-31 21:15 ` Dan Nagle
2002-07-31 22:36 ` Hyman Rosen
2002-07-31 22:23 ` Matthew Woodcraft
2002-08-02 7:21 ` Thomas Wolf
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox