% After seeing how complicated a calendar program can be, I was moved to
% fix the one I had been using. Although I haven't tested it extensively,
% I believe it gives the correct Gregorian dates from whenever the
% Gregorian began (which is different in different countries and in Russia
% was not until after 1917) until the year 4000 when a leap year is supposed
% to be omitted. A better correction would have been to omit leap years
% in all years divisible by 2000 and not by 6000, but this would have
% required immediate agreement and I guess that seemed too difficult.
%
% Obviously, the top line has to be edited to give the desired year.
%
% Michael Barr
% email: barr@barrs.org
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Start here %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\documentclass{article}
\textwidth 7.05in \oddsidemargin-.255in
\textheight=9in \headheight =0pt \topmargin=0pt\headsep=0pt
\pagestyle{empty}\thispagestyle{empty}
\newcount\yearnum
\immediate\write16{Please enter year?}
\message{>}
\read-1 to\yearn \yearnum\yearn
\newcount\febdays \febdays=28
\newcount\yearnuma
\newcount\yearnumb
\newcount\firstdate \newcount \lastdate \newcount \datenum
\font\gross=CMINCH %% <<= YEAR %%
\def\month#1#2#3{\initialdate{#1}{#2}%
\begin{tabular}{|rrrrrrr|} \hline
\multicolumn{7}{|c|}{#3}\\ \hline
Su&Mo&Tu&We&Th&Fr&Sa\\ \hline
\day{ 1}&\day{ 2}&\day{ 3}&\day{ 4}&\day{ 5}&\day{ 6}&\day{ 7}\\
\day{ 8}&\day{ 9}&\day{10}&\day{11}&\day{12}&\day{13}&\day{14}\\
\day{15}&\day{16}&\day{17}&\day{18}&\day{19}&\day{20}&\day{21}\\
\day{22}&\day{23}&\day{24}&\day{25}&\day{26}&\day{27}&\day{28}\\
\day{29}&\day{30}&\day{31}&\day{32}&\day{33}&\day{34}&\day{35}\\
\day{36}&\day{37}&\day{38}&\day{39}&\day{40}&\day{41}&\day{42}\\ \hline
\end{tabular}\global\advance\firstdate by #2
\ifnum\firstdate>35 \global\advance\firstdate by -35
\else\global\advance \firstdate by -28 \fi}
\def\day#1{\advance \datenum by#1
\ifnum\datenum>0 \ifnum\datenum>\lastdate\else\number\datenum \fi\fi}
\def\initialdate#1#2{\datenum=1 \advance\datenum by -#1 \lastdate=#2}
\newcount\xa\newcount\xb\newcount\xc
\newcount\ya\newcount\yb\newcount\yc\newcount\yd
\xa=0 \xb=235 {\multiply \xb by 2 \global\xc=\xb }
\yd=0 \yc=136 {\multiply \yc by 2 \global \yb=\yc }
{\multiply \yc by 3 \global \ya=\yc }
\begin{document}
\yearnuma=\yearnum
{\divide \yearnuma by 100\multiply\yearnuma by 100
\ifnum\yearnum=\yearnuma \divide \yearnuma by 100
\else\yearnuma=\yearnum
\fi
\yearnumb=\yearnuma \divide\yearnumb by 4 \multiply\yearnumb by 4
\ifnum\yearnumb=\yearnuma\global\febdays=29\fi}
\advance\yearnuma by -1 %Only year following leap year affected
\divide\yearnuma by 4 \advance\yearnuma by \yearnum
\yearnumb=\yearnum \advance\yearnumb by -1% Ditto
\divide\yearnumb by 100
\global\advance \yearnuma by -\yearnumb % subtract century years
\divide\yearnumb by 4 \advance\yearnuma by \yearnumb %add 4-century years
{\yearnum=\yearnuma \divide\yearnum by 7 \multiply\yearnum by -7
\global\advance\yearnuma by \yearnum} % correction mod 7
\firstdate=\yearnuma \advance\firstdate by 1% correct for year 1
\begin{center}
{\gross\number\yearnum }\end{center}\unitlength.01in
\begin{picture}(705,543)\put(\xa,\ya){\month{\firstdate}{31}{January}}
\put(\xb,\ya){\month{\firstdate}{\febdays}{February}}
\put(\xc,\ya){\month{\firstdate}{31}{March}}
\put(\xa,\yb){\month{\firstdate}{30}{April}}
\put(\xb,\yb){\month{\firstdate}{31}{May}}
\put(\xc,\yb){\month{\firstdate}{30}{June}}
\put(\xa,\yc){\month{\firstdate}{31}{July}}
\put(\xb,\yc){\month{\firstdate}{31}{August}}
\put(\xc,\yc){\month{\firstdate}{30}{September}}
\put(\xa,\yd){\month{\firstdate}{31}{October}}
\put(\xb,\yd){\month{\firstdate}{30}{November}}
\put(\xc,\yd){\month{\firstdate}{31}{December}}\end{picture}\newpage
\end{document}}