| 1 |
\ProvidesPackage{hijrical} |
| 2 |
[2010/07/12 v0.2 % |
| 3 |
Islamic calendar] |
| 4 |
|
| 5 |
\RequirePackage{calc} |
| 6 |
\RequirePackage{arabicnumbers} |
| 7 |
\@ifundefined{if@RTL}{\newif\if@RTL}{} |
| 8 |
\@ifpackageloaded{l3calc}{\PackageError{hijrical}{\MessageBreak |
| 9 |
Package l3calc is loaded, which replaces the functionality of |
| 10 |
calc. Computation of Hijri dates will not work properly with |
| 11 |
% FIXME by Arthur: François couldn’t possibly mean ‘l3calc’ on the |
| 12 |
% following line :-) Find out if he meant ‘calc’. |
| 13 |
l3calc! The latest version of expl3 on CTAN no longer loads |
| 14 |
l3calc. Please update expl3! |
| 15 |
}{}}{} |
| 16 |
|
| 17 |
\@ifundefined{@Remainder}{\input{cal-util.def}}{} |
| 18 |
|
| 19 |
%% The following functions are straightforward implementation |
| 20 |
%% of Reingold & Dershowitz, Calendrical Calculations, The Millennium Edition |
| 21 |
%% |
| 22 |
|
| 23 |
\def\@FixedFromHijri#1#2#3#4{% year,month,day,counter |
| 24 |
\@ifundefined{c@#4}{\newcounter{#4}}{}% |
| 25 |
\setcounter{tmpA}{#2/2}% see errata of Reingold+Dershowitz |
| 26 |
%\message{tmpA is \thetmpA}% |
| 27 |
\setcounter{tmpB}{(3+11*#1)/30}% |
| 28 |
%\message{tmpB is \thetmpB}% |
| 29 |
\setcounter{#4}{227014+(#1-1)*354+\value{tmpB}+(29*(#2-1))+\value{tmpA}+#3}% |
| 30 |
} |
| 31 |
|
| 32 |
\newcounter{Hijriday}\newcounter{Hijrimonth}\newcounter{Hijriyear} |
| 33 |
|
| 34 |
\def\HijriFromGregorian#1#2#3{% year,month,day |
| 35 |
\@FixedFromGregorian{#1}{#2}{#3}{RDdate}% |
| 36 |
\setcounter{Hijriyear}{(30*(\value{RDdate}-227015)+10646)/10631}% |
| 37 |
\@FixedFromHijri{\value{Hijriyear}}{1}{1}{tmpx}% |
| 38 |
%\message{tmpx is \thetmpx}% |
| 39 |
\setcounter{tmpB}{\value{RDdate}-\value{tmpx}}% |
| 40 |
%\message{tmpB is \thetmpB}% |
| 41 |
\setcounter{Hijrimonth}{((11*\value{tmpB})+330)/325}% |
| 42 |
\@FixedFromHijri{\value{Hijriyear}}{\value{Hijrimonth}}{1}{tmpy}% |
| 43 |
%\message{tmpy is \thetmpy}% |
| 44 |
\setcounter{Hijriday}{1+\value{RDdate}-\value{tmpy}}% |
| 45 |
} |
| 46 |
|
| 47 |
%\HijriFromGregorian{\year}{\month}{\day}% |
| 48 |
|
| 49 |
%\def\PlainHijritoday{% |
| 50 |
%\theHijriday.\theHijrimonth.\theHijriyear} |
| 51 |
|
| 52 |
\def\Hijridate#1#2#3{% |
| 53 |
\HijriFromGregorian{#1}{#2}{#3}% |
| 54 |
\FormatHijriDate} |
| 55 |
|
| 56 |
% added option \Hijritoday[n] (default 0) for adjusting the date + n days |
| 57 |
\@ifundefined{@hijri@correction}{\gdef\@hijri@correction{0}}{} |
| 58 |
\newcommand\Hijritoday[1][\@hijri@correction]{% |
| 59 |
\@ifundefined{c@adj@day}{\global\newcounter{adj@day}}{}% |
| 60 |
\setcounter{adj@day}{\the\day+#1}% |
| 61 |
\Hijridate{\year}{\month}{\value{adj@day}}} |
| 62 |
%\def\Hijritoday{\Hijridate{\year}{\month}{\day}} |
| 63 |
\let\hijritoday=\Hijritoday |
| 64 |
%FIXME necessary? |
| 65 |
%\def\Hijrisetreg{% |
| 66 |
% \HijriFromGregorian{\year}{\month}{\day}} |
| 67 |
|
| 68 |
\def\HijriMonthTranslit#1{\ifcase#1\or Muḥarram\or Ṣafar\or Rabīʿ I\or Rabīʿ II\or% |
| 69 |
Jumādā I\or Jumādā II\or Rajab\or Shaʿbān\or Ramaḍān\or% |
| 70 |
Shawwāl\or Dhū ’l-Qaʿda\or Dhū ’l-Ḥijja\fi} |
| 71 |
|
| 72 |
\def\HijriMonthArabic#1{\ifcase#1\or محرم\or صفر\or ربيع الأول\or ربيع الآخر\or% |
| 73 |
جمادى الأولى\or جمادى الآخرة\or رجب\or شعبان\or رمضان\or% |
| 74 |
شوال\or ذو القعدة\or ذو الحجة\fi} |
| 75 |
|
| 76 |
%% This macro is now locale-aware! |
| 77 |
\def\FormatHijriDate{% |
| 78 |
\@ifundefined{FormatHijriDate@\languagename}% |
| 79 |
{\if@RTL\FormatHijriDate@defaultRTL\else\FormatHijriDate@defaultLTR\fi}% |
| 80 |
{\csname FormatHijriDate@\languagename\endcsname}} |
| 81 |
|
| 82 |
\newcommand\DefineFormatHijriDate[2]{% |
| 83 |
\@namedef{FormatHijriDate@#1}{#2}} |
| 84 |
|
| 85 |
% we provide this as a reasonable default. |
| 86 |
% Further definitions are in polyglossia’s language definition files. |
| 87 |
\DefineFormatHijriDate{defaultRTL}{\@ensure@RTL{% |
| 88 |
\arabicdigits{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\arabicdigits{\value{Hijriyear}}}} |
| 89 |
|
| 90 |
\DefineFormatHijriDate{defaultLTR}{% |
| 91 |
\number\value{Hijriday}\space\HijriMonthTranslit{\value{Hijrimonth}}\space\number\value{Hijriyear}} |
| 92 |
\endinput |
| 93 |
|
| 94 |
%TODO |
| 95 |
\def\CYearsFromHijri#1{%yields the corr julian or gregorian years |
| 96 |
} % e.g. \CYearsFromHijri{425} -> 1033/34 |