summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xelatex/polyglossia/farsical.sty
blob: 8768825308ff18ab46f3aca8f9cffba6a828ed81 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
\ProvidesPackage{farsical}
        [2008/07/02 v0.1 %
         Farsi (jalali) calendar]
\RequirePackage{bidi,calc}

%TODO - rewrite completely using use calc 
%%    - use Reingold & Dershowitz ME
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Modified from Arabiftoday.sty which is part of the Arabi package:
%%%  Copyright (C) 2006 Youssef Jabri
%%% itself a modification of the code in the FarsiTeX system:
%%%  Copyright (C) 1996 Hassan Abolhassani
%%%  Copyright (C) 1996-2001 Roozbeh Pournader <roozbeh@sharif.edu>
%%%  Copyright (C) 2000-2001 Behdad Esfahbod <behdad@bamdad.org>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifJALALI@leap \newif\ifJALALI@kabiseh
\newcount\JALALI@i  \newcount\JALALI@y  \newcount\JALALI@m  \newcount\JALALI@d
\newcount\JALALI@latini    \newcount\JALALI@farsii
\newcount\JALALI@latinii   \newcount\JALALI@farsiii
\newcount\JALALI@latiniii  \newcount\JALALI@farsiiii
\newcount\JALALI@latiniv   \newcount\JALALI@farsiiv
\newcount\JALALI@latinv    \newcount\JALALI@farsiv
\newcount\JALALI@latinvi   \newcount\JALALI@farsivi
\newcount\JALALI@latinvii  \newcount\JALALI@farsivii
\newcount\JALALI@latinviii \newcount\JALALI@farsiviii
\newcount\JALALI@latinix   \newcount\JALALI@farsiix
\newcount\JALALI@latinx    \newcount\JALALI@farsix
\newcount\JALALI@latinxi   \newcount\JALALI@farsixi
\newcount\JALALI@latinxii  \newcount\JALALI@farsixii
                           \newcount\JALALI@farsixiii

\newcount\JALALI@temp
\newcount\JALALI@temptwo
\newcount\JALALI@tempthree
\newcount\JALALI@yModHundred
\newcount\JALALI@thirtytwo
\newcount\JALALI@dn
\newcount\JALALI@sn
\newcount\JALALI@mminusone

% \ftoday renamed to \Jalalitoday - FC
\def\Jalalitoday{%
\JALALI@y=\year \JALALI@m=\month \JALALI@d=\day
%
\JALALI@temp=\JALALI@y
\divide\JALALI@temp by 100\relax
\multiply\JALALI@temp by 100\relax
\JALALI@yModHundred=\JALALI@y
\advance\JALALI@yModHundred by -\JALALI@temp\relax
%
\ifodd\JALALI@yModHundred
   \JALALI@leapfalse
\else
   \JALALI@temp=\JALALI@yModHundred
   \divide\JALALI@temp by 2\relax
   \ifodd\JALALI@temp\JALALI@leapfalse
   \else
      \ifnum\JALALI@yModHundred=0%
         \JALALI@temp=\JALALI@y
         \divide\JALALI@temp by 400\relax
         \multiply\JALALI@temp by 400\relax
         \ifnum\JALALI@y=\JALALI@temp\JALALI@leaptrue\else\JALALI@leapfalse\fi
      \else\JALALI@leaptrue
      \fi
   \fi
\fi
%
\JALALI@latini=31\relax
\ifJALALI@leap
  \JALALI@latinii = 29\relax
\else
  \JALALI@latinii = 28\relax
\fi
\JALALI@latiniii = 31\relax
\JALALI@latiniv  = 30\relax
\JALALI@latinv = 31\relax
\JALALI@latinvi = 30\relax
\JALALI@latinvii = 31\relax
\JALALI@latinviii = 31\relax
\JALALI@latinix = 30\relax
\JALALI@latinx = 31\relax
\JALALI@latinxi = 30\relax
\JALALI@latinxii = 31\relax
%
\JALALI@thirtytwo=32\relax
%
\JALALI@temp=\JALALI@y
\advance\JALALI@temp by -17\relax
\JALALI@temptwo=\JALALI@temp
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 33\relax
\advance\JALALI@temp by -\JALALI@temptwo
\ifnum\JALALI@temp=\JALALI@thirtytwo\JALALI@kabisehfalse
\else
   \JALALI@temptwo=\JALALI@temp
   \divide\JALALI@temptwo by 4\relax
   \multiply\JALALI@temptwo by 4\relax
   \advance\JALALI@temp by -\JALALI@temptwo
   \ifnum\JALALI@temp=\z@\JALALI@kabisehtrue\else\JALALI@kabisehfalse\fi
\fi
%
% --BE
% In fact farsii is equal to the Leap years from a fixed year to the last
% year minus the Kabise years from a fixed year to the last year plus a const.
%
\JALALI@tempthree=\JALALI@y                 % Number of Leap years
\advance\JALALI@tempthree by -1
\JALALI@temp=\JALALI@tempthree              % T := (MY-1) div 4
\divide\JALALI@temp by 4\relax
\JALALI@temptwo=\JALALI@tempthree           % T := T - ((MY-1) div 100)
\divide\JALALI@temptwo by 100\relax
\advance\JALALI@temp by -\JALALI@temptwo
\JALALI@temptwo=\JALALI@tempthree           % T := T + ((MY-1) div 400)
\divide\JALALI@temptwo by 400\relax
\advance\JALALI@temp by \JALALI@temptwo
\advance\JALALI@tempthree by -611       % Number of Kabise years
\JALALI@temptwo=\JALALI@tempthree           % T := T - ((SY+10) div 33) * 8
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 8\relax
\advance\JALALI@temp by -\JALALI@temptwo
\JALALI@temptwo=\JALALI@tempthree           %
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 33\relax
\advance\JALALI@tempthree by -\JALALI@temptwo
\ifnum\JALALI@tempthree=32\advance\JALALI@temp by 1\fi % if (SY+10) mod 33=32 then Inc(T);
\divide\JALALI@tempthree by 4\relax     % T := T - ((SY+10) mod 33) div 4
\advance\JALALI@temp by -\JALALI@tempthree
\advance\JALALI@temp by -137            % T := T - 137  Adjust the value
\JALALI@farsii=31
\advance\JALALI@farsii by -\JALALI@temp                 % now 31 - T is the farsii
%
\JALALI@farsiii = 30\relax
\ifJALALI@kabiseh
  \JALALI@farsiiii = 30\relax
\else
  \JALALI@farsiiii = 29\relax
\fi
\JALALI@farsiiv  = 31\relax
\JALALI@farsiv   = 31\relax
\JALALI@farsivi  = 31\relax
\JALALI@farsivii = 31\relax
\JALALI@farsiviii= 31\relax
\JALALI@farsiix  = 31\relax
\JALALI@farsix   = 30\relax
\JALALI@farsixi  = 30\relax
\JALALI@farsixii = 30\relax
\JALALI@farsixiii= 30\relax
%
\JALALI@dn= 0\relax
\JALALI@sn= 0\relax
\JALALI@mminusone=\JALALI@m
\advance\JALALI@mminusone by -1\relax
%
\JALALI@i=0\relax
\ifnum\JALALI@i < \JALALI@mminusone
\loop
\advance \JALALI@i by 1\relax
\advance\JALALI@dn by \csname JALALI@latin\romannumeral\the\JALALI@i\endcsname
\ifnum\JALALI@i<\JALALI@mminusone \repeat
\fi
\advance \JALALI@dn by \JALALI@d
%
\JALALI@i=1\relax
\JALALI@sn = \JALALI@farsii
\ifnum \JALALI@sn<\JALALI@dn
\loop
\advance \JALALI@i by 1\relax
\advance\JALALI@sn by \csname JALALI@farsi\romannumeral\the\JALALI@i\endcsname
\ifnum \JALALI@sn<\JALALI@dn \repeat
\fi
\ifnum \JALALI@i < 4
   \JALALI@m = 9 \advance\JALALI@m by \JALALI@i
   \advance \JALALI@y by -622\relax
\else
   \JALALI@m = \JALALI@i \advance \JALALI@m by -3\relax
   \advance \JALALI@y by -621\relax
\fi
\advance\JALALI@sn by -\csname JALALI@farsi\romannumeral\the\JALALI@i%
\endcsname
\ifnum\JALALI@i = 1
  \JALALI@d = \JALALI@dn \advance \JALALI@d by 30 \advance\JALALI@d by -\JALALI@farsii
\else
  \JALALI@d = \JALALI@dn \advance \JALALI@d by -\JALALI@sn
\fi
%% DATE FORMATTING
\if@rl{\farsinumber\JALALI@d\space%
\Jalalimonth{\JALALI@m}\space\farsinumber\JALALI@y}%
\else%
\number\JALALI@d\space\JalalimonthEnglish{\JALALI@m}%
\space\number\JALALI@y%
\fi
}
%%%
\def\Jalalimonth#1{\ifcase#1\or فروردین\or 
اردیبهشت\or خرداد\or تیر\or مرداد\or شهریور
\or مهر\or آبان\or آذر\or دی\or بهمن\or اسفند
\fi}
\def\JalalimonthEnglish#1{\ifcase#1%
\or Farvardīn\or Ordībehesht\or Khordād\or Tīr
\or Mordād\or Shahrīvar\or Mihr\or Ābān\or Āzar
\or Dai\or Bahman\or Esfand\fi}
\endinput