summaryrefslogtreecommitdiff
path: root/dviware/umddvi/doc/dow.tex
blob: 866824767978ae960ad008ef8bbe41530a6434fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% From: minow@decvax.UUCP (Martin Minow)
%
% \DayOfWeek	expands to the day of the week ("Sunday", etc.)
%
\newcount\dow
\def\DayOfWeek{\ifcase\dow Sunday\or Monday\or Tuesday\or Wednesday\or
    Thursday\or Friday\or Saturday\fi}

%
% Calculate day of the week (0=Sunday, 1=Monday, etc.), result
% into \dow.
%
{ \countdef\leap=1			% Leap year fingaler
  \countdef\x=2				% Temp register
  \countdef\y=3 			% Another temp register
%		leap = year + (month - 14)/12;
  \leap=\month \advance\leap by -14 \divide\leap by 12 \advance\leap by \year
%		dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  \dow=\month \advance\dow by 10 \y=\dow \divide\y by 13 \multiply\y by 12
  \advance\dow by -\y \multiply\dow by 13 \advance\dow by -1 \divide\dow by 5
%		dow += day + 77 + 5 * (leap % 100)/4
  \advance\dow by \day \advance\dow by 77
  \x=\leap \y=\x \divide\y by 100 \multiply\y by 100 \advance\x by -\y
  \multiply \x by 5 \divide\x by 4 \advance\dow by \x
%		dow += leap / 400
  \x=\leap \divide\x by 400 \advance\dow by \x
%		dow -= leap / 100 * 2;
%		dow = (dow % 7)
  \x=\leap \divide\x by 100 \multiply\x by 2 \advance\dow by -\x
  \x=\dow \divide\x by 7 \multiply\x by 7 \advance\dow by -\x
  \global\dow=\dow
}