[net.sources] Day of Week Alg

demillo@uwmacc.UUCP (Rob DeMillo) (12/05/84)

News saved in /usr1/macc/demillo/dead.article

ecl@ahuta.UUCP (e.leeper) (12/12/84)

REFERENCES:  <538@uwmacc.UUCP>

Re: Perpetual Calendar formula wanted

For people asking about perpetual calendar formulae, this one was in
the Webster's dictionary when I was growing up.  I memorized it and can
do it in my head.  Except for the fact that I do mod 7 reductions as 
I go along, the algorithm I use in my head is the same as the
following.

Break up the date as follows:

MONTH DD, CCYY

For Pearl Harbor day
MONTH = Dec.
DD = 7
CC = 19
YY = 41

Let [[x]] be the integer part of x.
Let y%z be y mod z.

To get the day of the week compute the following:

day = (cent(CC) + [[1.25 * YY]] + mon(MONTH) + DD - fudge)%7

cent(19) = 0
cent(18) = 2
cent(17) = 4
cent(16) = 6

month(Apr. or Jul.) = 0
month(Jan. or Oct.) = 1
month(May) = 2
month(Aug.) = 3
month(Feb. or Mar. or Oct.) = 4
month(June) = 5
month(Sept. or Dec.) = 6

fudge = 1 the first two months of a leap year, otherwise 0.

if day = 0, then the day is a Saturday,
if day = 1, then the day is a Sunday,
if day = 2, then the day is a Monday, ...

So for Pearl Harbor Day you get
day = (0 + 51 + 6 + 7 - 0)%7 = 1

					(Evelyn C. Leeper for)
					Mark R. Leeper
					...ihnp4!lznv!mrl

lwall@sdcrdcf.UUCP (Larry Wall) (12/14/84)

> month(Apr. or Jul.) = 0
> month(Jan. or Oct.) = 1
> month(May) = 2
> month(Aug.) = 3
> month(Feb. or Mar. or Oct.) = 4
> month(June) = 5
> month(Sept. or Dec.) = 6

Shouldn't that be "Feb. or Mar. or Nov."?

Larry Wall
{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall