| 1 |
%%%%%%%%%%%%% cal-util.def %%%%%%%%%%%%%%%% |
| 2 |
% Macros shared by hijrical and hebrewcal % |
| 3 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4 |
% the following is adapted from hebcal.sty in babel |
| 5 |
\def\@Remainder#1#2#3{% |
| 6 |
#3 = #1% % c = a |
| 7 |
\divide #3 by #2% % c = a/b |
| 8 |
\multiply #3 by -#2% % c = -b(a/b) |
| 9 |
\advance #3 by #1}% % c = a - b(a/b) |
| 10 |
\newif\if@Divisible |
| 11 |
\def\@CheckIfDivisible#1#2{% |
| 12 |
{% |
| 13 |
\countdef\tmpx=0% % temporary variable |
| 14 |
\@Remainder{#1}{#2}{\tmpx}% |
| 15 |
\ifnum\tmpx=0% |
| 16 |
\global\@Divisibletrue% |
| 17 |
\else% |
| 18 |
\global\@Divisiblefalse% |
| 19 |
\fi}} |
| 20 |
\newif\if@GregorianLeap |
| 21 |
\def\@CheckIfGregorianLeap#1{% |
| 22 |
{% |
| 23 |
\@CheckIfDivisible{#1}{4}% |
| 24 |
\if@Divisible% |
| 25 |
\@CheckIfDivisible{#1}{100}% |
| 26 |
\if@Divisible% |
| 27 |
\@CheckIfDivisible{#1}{400}% |
| 28 |
\if@Divisible% |
| 29 |
\global\@GregorianLeaptrue% |
| 30 |
\else% |
| 31 |
\global\@GregorianLeapfalse% |
| 32 |
\fi% |
| 33 |
\else% |
| 34 |
\global\@GregorianLeaptrue% |
| 35 |
\fi% |
| 36 |
\else% |
| 37 |
\global\@GregorianLeapfalse% |
| 38 |
\fi% |
| 39 |
}} |
| 40 |
%% |
| 41 |
|
| 42 |
\newcounter{tmpA}\newcounter{tmpB} |
| 43 |
\newcounter{tmpC}\newcounter{tmpD} |
| 44 |
\newcounter{tmpE}\newcounter{tmpF} |
| 45 |
|
| 46 |
|
| 47 |
%% This is an algorithm from Reingold & Dershowitz, |
| 48 |
%% Calendrical Calculations, The Millennium Edition |
| 49 |
%% |
| 50 |
\def\@FixedFromGregorian#1#2#3#4{% |
| 51 |
\setcounter{tmpA}{(#1-1)*365}% |
| 52 |
\setcounter{tmpB}{(#1-1)/4}% |
| 53 |
\setcounter{tmpC}{(#1-1)/100}% |
| 54 |
\setcounter{tmpD}{(#1-1)/400}% |
| 55 |
\setcounter{tmpE}{(367*#2-362)/12}% |
| 56 |
\ifnum#2<3% |
| 57 |
\setcounter{tmpF}{0}% |
| 58 |
\else% |
| 59 |
\@CheckIfGregorianLeap{#1}% |
| 60 |
\if@GregorianLeap% |
| 61 |
\setcounter{tmpF}{-1}% |
| 62 |
\else% |
| 63 |
\setcounter{tmpF}{-2}% |
| 64 |
\fi% |
| 65 |
\fi% |
| 66 |
\@ifundefined{c@#4}{\global\newcounter{#4}}{}% |
| 67 |
\setcounter{#4}{\value{tmpA}+\value{tmpB}-\value{tmpC}+\value{tmpD}+\value{tmpE}+\value{tmpF}+#3}% |
| 68 |
} |
| 69 |
\endinput |