ruby-calendrical 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +26 -0
- data/README +72 -0
- data/README.en +76 -0
- data/example/cal.rb +39 -0
- data/ext/calendrical/MANIFEST +10 -0
- data/ext/calendrical/calendrical.c +1197 -0
- data/ext/calendrical/calendrical.h +99 -0
- data/ext/calendrical/calendrical2.c +802 -0
- data/ext/calendrical/calendrical2.h +72 -0
- data/ext/calendrical/calendricalmodule.c +1796 -0
- data/ext/calendrical/depend +4 -0
- data/ext/calendrical/extconf.rb +2 -0
- data/ext/calendrical/qref.c +20655 -0
- data/ext/calendrical/qref.h +13 -0
- metadata +58 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
/*
|
2
|
+
calendrical.h: Written by Tadayoshi Funaba 1997-2000,2014
|
3
|
+
|
4
|
+
This code is in the public domain, but any use of it
|
5
|
+
should publically acknowledge its source.
|
6
|
+
|
7
|
+
$Id: calendrical.h,v 1.6 2014-04-08 19:27:31+09 tadf Exp $
|
8
|
+
*/
|
9
|
+
|
10
|
+
#if !defined(__GNUC__) \
|
11
|
+
|| !( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))
|
12
|
+
#undef __attribute__
|
13
|
+
#define __attribute__(x)
|
14
|
+
#endif
|
15
|
+
|
16
|
+
extern int gregorian_leap_year(int year) __attribute__ ((const));
|
17
|
+
extern int gregorian_last_day_of_month(int year, int month) __attribute__ ((const));
|
18
|
+
extern int gregorian_to_rd(int year, int month, int day) __attribute__ ((const));
|
19
|
+
extern void rd_to_gregorian(int date, int *ryear, int *rmonth, int *rday);
|
20
|
+
extern int kday_on_or_before(int date, int k) __attribute__ ((const));
|
21
|
+
extern int iso_to_rd(int year, int week, int day) __attribute__ ((const));
|
22
|
+
extern void rd_to_iso(int date, int *ryear, int *rweek, int *rday);
|
23
|
+
extern int julian_leap_year(int year) __attribute__ ((const));
|
24
|
+
extern int julian_last_day_of_month(int year, int month) __attribute__ ((const));
|
25
|
+
extern int julian_to_rd(int year, int month, int day) __attribute__ ((const));
|
26
|
+
extern void rd_to_julian(int date, int *ryear, int *rmonth, int *rday);
|
27
|
+
extern int islamic_leap_year(int year) __attribute__ ((const));
|
28
|
+
extern int islamic_last_day_of_month(int year, int month) __attribute__ ((const));
|
29
|
+
extern int islamic_to_rd(int year, int month, int day) __attribute__ ((const));
|
30
|
+
extern void rd_to_islamic(int date, int *ryear, int *rmonth, int *rday);
|
31
|
+
extern int hebrew_leap_year(int year) __attribute__ ((const));
|
32
|
+
extern int hebrew_last_month_of_year(int year) __attribute__ ((const));
|
33
|
+
extern int hebrew_last_day_of_month(int year, int month) __attribute__ ((const));
|
34
|
+
extern int hebrew_calendar_elapsed_days(int year) __attribute__ ((const));
|
35
|
+
extern int hebrew_days_in_year(int year) __attribute__ ((const));
|
36
|
+
extern int long_heshvan(int year) __attribute__ ((const));
|
37
|
+
extern int short_kislev(int year) __attribute__ ((const));
|
38
|
+
extern int hebrew_to_rd(int year, int month, int day) __attribute__ ((const));
|
39
|
+
extern void rd_to_hebrew(int date, int *ryear, int *rmonth, int *rday);
|
40
|
+
#if !defined(PLUTO) && !defined(MODULE)
|
41
|
+
extern int independence_day(int year) __attribute__ ((const));
|
42
|
+
#endif
|
43
|
+
#ifndef PLUTO
|
44
|
+
extern int nth_kday(int year, int month, int n, int k) __attribute__ ((const));
|
45
|
+
#endif
|
46
|
+
#if !defined(PLUTO) && !defined(MODULE)
|
47
|
+
extern int labor_day(int year) __attribute__ ((const));
|
48
|
+
extern int memorial_day(int year) __attribute__ ((const));
|
49
|
+
extern int daylight_savings_start(int year) __attribute__ ((const));
|
50
|
+
extern int daylight_savings_end(int year) __attribute__ ((const));
|
51
|
+
extern int christmas(int year) __attribute__ ((const));
|
52
|
+
extern int advent(int year) __attribute__ ((const));
|
53
|
+
extern int epiphany(int year) __attribute__ ((const));
|
54
|
+
extern int eastern_orthodox_christmas(int year) __attribute__ ((const));
|
55
|
+
#endif /* not PLUTO and not MODULE */
|
56
|
+
extern int nicaean_rule_easter(int year) __attribute__ ((const));
|
57
|
+
extern int easter(int year) __attribute__ ((const));
|
58
|
+
#if !defined(PLUTO) && !defined(MODULE)
|
59
|
+
extern int pentecost(int year) __attribute__ ((const));
|
60
|
+
extern void islamic_date(int year, int month, int day, int date[3]);
|
61
|
+
extern void mulad_al_nabi(int year, int date[3]);
|
62
|
+
extern int yom_kippur(int year) __attribute__ ((const));
|
63
|
+
extern int passover(int year) __attribute__ ((const));
|
64
|
+
extern int purim(int year) __attribute__ ((const));
|
65
|
+
extern int ta_anit_esther(int year) __attribute__ ((const));
|
66
|
+
extern int tisha_b_av(int year) __attribute__ ((const));
|
67
|
+
extern int hebrew_birthday(int birth_year, int birth_month, int birth_day, int year) __attribute__ ((const));
|
68
|
+
extern int yahrzeit(int death_year, int death_month, int death_day, int year) __attribute__ ((const));
|
69
|
+
#endif /* not PLUTO and not MODULE */
|
70
|
+
extern int mayan_long_count_to_rd(int baktun, int katun, int tun, int uinal, int kin) __attribute__ ((const));
|
71
|
+
extern void rd_to_mayan_long_count(int date, int *rbaktun, int *rkatun, int *rtun, int *ruinal, int *rkin);
|
72
|
+
extern void rd_to_mayan_haab(int date, int *rmonth, int *rday);
|
73
|
+
extern int mayan_haab_difference(int month1, int day1, int month2, int day2) __attribute__ ((const));
|
74
|
+
extern int mayan_haab_on_or_before(int haab_month, int haab_day, int date) __attribute__ ((const));
|
75
|
+
extern void rd_to_mayan_tzolkin(int date, int *rname, int *rnumber);
|
76
|
+
extern int mayan_tzolkin_difference(int name1, int number1, int name2, int number2) __attribute__ ((const));
|
77
|
+
extern int mayan_tzolkin_on_or_before(int name, int number, int date) __attribute__ ((const));
|
78
|
+
extern int mayan_haab_tzolkin_on_or_before(int month, int day, int name, int number, int date) __attribute__ ((const));
|
79
|
+
extern int french_leap_year(int year) __attribute__ ((const));
|
80
|
+
extern int french_last_day_of_month(int year, int month) __attribute__ ((const));
|
81
|
+
extern int french_to_rd(int year, int month, int day) __attribute__ ((const));
|
82
|
+
extern void rd_to_french(int date, int *ryear, int *rmonth, int *rday);
|
83
|
+
extern double solar_longitude(double days) __attribute__ ((const));
|
84
|
+
extern double zodiac(double days) __attribute__ ((const));
|
85
|
+
extern void rd_to_old_hindu_solar(int date, int *ryear, int *rmonth, int *rday);
|
86
|
+
extern int old_hindu_solar_to_rd(int year, int month, int day) __attribute__ ((const));
|
87
|
+
extern double lunar_longitude(double days) __attribute__ ((const));
|
88
|
+
extern double lunar_phase(double days) __attribute__ ((const));
|
89
|
+
extern double new_moon(double days) __attribute__ ((const));
|
90
|
+
extern void rd_to_old_hindu_lunar(int date, int *ryear, int *rmonth, int *rleapmonth, int *rday);
|
91
|
+
extern int old_hindu_lunar_precedes(int year1, int month1, int leap1, int day1, int year2, int month2, int leap2, int day2) __attribute__ ((const));
|
92
|
+
extern int old_hindu_lunar_to_rd(int year, int month, int leapmonth, int day) __attribute__ ((const));
|
93
|
+
|
94
|
+
|
95
|
+
/*
|
96
|
+
Local Variables:
|
97
|
+
c-basic-offset: 2
|
98
|
+
End:
|
99
|
+
*/
|
@@ -0,0 +1,802 @@
|
|
1
|
+
/*
|
2
|
+
calendrical2.c (beta): Written by Tadayoshi Funaba 1997,1999-2002,2014
|
3
|
+
|
4
|
+
This code is in the public domain, but any use of it
|
5
|
+
should publically acknowledge its source.
|
6
|
+
|
7
|
+
$Id: calendrical2.c,v 1.10 2014-04-27 09:42:02+09 tadf Exp $
|
8
|
+
*/
|
9
|
+
|
10
|
+
#define MODULE
|
11
|
+
|
12
|
+
#ifndef NULL
|
13
|
+
#define NULL 0
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <math.h>
|
18
|
+
#include "calendrical.h"
|
19
|
+
#include "calendrical2.h"
|
20
|
+
|
21
|
+
static div_t
|
22
|
+
divmod(int m, int n)
|
23
|
+
{
|
24
|
+
div_t d;
|
25
|
+
|
26
|
+
d = div(m, n);
|
27
|
+
if ((m < 0) != (n < 0) && d.rem != 0) {
|
28
|
+
d.quot -= 1;
|
29
|
+
d.rem += n;
|
30
|
+
}
|
31
|
+
return d;
|
32
|
+
}
|
33
|
+
|
34
|
+
#undef quotient
|
35
|
+
#define quotient(m, n) i_quotient(m, n)
|
36
|
+
static int
|
37
|
+
i_quotient(int m, int n)
|
38
|
+
{
|
39
|
+
return divmod(m, n).quot;
|
40
|
+
}
|
41
|
+
#undef mod
|
42
|
+
#define mod(m, n) i_mod(m, n)
|
43
|
+
static int
|
44
|
+
i_mod(int m, int n)
|
45
|
+
{
|
46
|
+
return divmod(m, n).rem;
|
47
|
+
}
|
48
|
+
#undef oddp
|
49
|
+
#define oddp(n) ((n) % 2)
|
50
|
+
|
51
|
+
static int
|
52
|
+
approximate(int x, int y)
|
53
|
+
{
|
54
|
+
return quotient(x, (x < 0) ? (y - 1) : y);
|
55
|
+
}
|
56
|
+
|
57
|
+
int
|
58
|
+
world_leap_year(int year)
|
59
|
+
{
|
60
|
+
return
|
61
|
+
mod(year, 4) == 0 &&
|
62
|
+
!(mod(year, 400) == 100 ||
|
63
|
+
mod(year, 400) == 200 ||
|
64
|
+
mod(year, 400) == 300);
|
65
|
+
}
|
66
|
+
|
67
|
+
int
|
68
|
+
world_last_day_of_month(int year, int month)
|
69
|
+
{
|
70
|
+
if (month == 6 && world_leap_year(year))
|
71
|
+
return 31;
|
72
|
+
switch (month) {
|
73
|
+
case 1: return 31;
|
74
|
+
case 2: return 30;
|
75
|
+
case 3: return 30;
|
76
|
+
case 4: return 31;
|
77
|
+
case 5: return 30;
|
78
|
+
case 6: return 30;
|
79
|
+
case 7: return 31;
|
80
|
+
case 8: return 30;
|
81
|
+
case 9: return 30;
|
82
|
+
case 10: return 31;
|
83
|
+
case 11: return 30;
|
84
|
+
case 12: return 31;
|
85
|
+
default: return 0;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
int
|
90
|
+
world_to_rd(int year, int month, int day)
|
91
|
+
{
|
92
|
+
int sumres;
|
93
|
+
|
94
|
+
{
|
95
|
+
int temp, m;
|
96
|
+
for (temp = 0, m = 1;
|
97
|
+
(m < month);
|
98
|
+
temp = temp + world_last_day_of_month(year, m), m++)
|
99
|
+
;
|
100
|
+
sumres = temp;
|
101
|
+
}
|
102
|
+
return day
|
103
|
+
+ sumres
|
104
|
+
+ (365 * (year - 1))
|
105
|
+
+ quotient(year - 1, 4)
|
106
|
+
- quotient(year - 1, 100)
|
107
|
+
+ quotient(year - 1, 400);
|
108
|
+
}
|
109
|
+
|
110
|
+
void
|
111
|
+
rd_to_world(int date, int *ryear, int *rmonth, int *rday)
|
112
|
+
{
|
113
|
+
int approx, month, day, year;
|
114
|
+
int sumres1, sumres2;
|
115
|
+
|
116
|
+
approx = approximate(date, 366);
|
117
|
+
{
|
118
|
+
int temp, y;
|
119
|
+
for (temp = 0, y = approx;
|
120
|
+
(date >= world_to_rd(1 + y, 1, 1));
|
121
|
+
temp = temp + 1, y++)
|
122
|
+
;
|
123
|
+
sumres1 = temp;
|
124
|
+
}
|
125
|
+
year = approx
|
126
|
+
+ sumres1;
|
127
|
+
{
|
128
|
+
int temp, m;
|
129
|
+
for (temp = 0, m = 1;
|
130
|
+
(date > world_to_rd
|
131
|
+
(year, m, world_last_day_of_month(year, m)));
|
132
|
+
temp = temp + 1, m++)
|
133
|
+
;
|
134
|
+
sumres2 = temp;
|
135
|
+
}
|
136
|
+
month = 1
|
137
|
+
+ sumres2;
|
138
|
+
day = date
|
139
|
+
- (world_to_rd(year, month, 1) - 1);
|
140
|
+
if (rmonth)
|
141
|
+
*rmonth = month;
|
142
|
+
if (rday)
|
143
|
+
*rday = day;
|
144
|
+
if (ryear)
|
145
|
+
*ryear = year;
|
146
|
+
}
|
147
|
+
|
148
|
+
int
|
149
|
+
rd_to_world_day_of_week(int date)
|
150
|
+
{
|
151
|
+
int month, day, year;
|
152
|
+
|
153
|
+
rd_to_world(date, &year, &month, &day);
|
154
|
+
if (month == 12 && day == 31)
|
155
|
+
return 7;
|
156
|
+
else if (month == 6 && day == 31)
|
157
|
+
return 8;
|
158
|
+
else
|
159
|
+
switch ((month - 1) % 3) {
|
160
|
+
case 0: return (day - 1) % 7;
|
161
|
+
case 1: return (day + 2) % 7;
|
162
|
+
case 2: return (day + 4) % 7;
|
163
|
+
}
|
164
|
+
/*NOTREACHED*/
|
165
|
+
return -1;
|
166
|
+
}
|
167
|
+
|
168
|
+
int
|
169
|
+
coptic_leap_year(int year)
|
170
|
+
{
|
171
|
+
return mod(year, 4) == 3;
|
172
|
+
}
|
173
|
+
|
174
|
+
int
|
175
|
+
coptic_last_day_of_month(int year, int month)
|
176
|
+
{
|
177
|
+
if (month == 13 && coptic_leap_year(year))
|
178
|
+
return 6;
|
179
|
+
switch (month) {
|
180
|
+
case 1: return 30;
|
181
|
+
case 2: return 30;
|
182
|
+
case 3: return 30;
|
183
|
+
case 4: return 30;
|
184
|
+
case 5: return 30;
|
185
|
+
case 6: return 30;
|
186
|
+
case 7: return 30;
|
187
|
+
case 8: return 30;
|
188
|
+
case 9: return 30;
|
189
|
+
case 10: return 30;
|
190
|
+
case 11: return 30;
|
191
|
+
case 12: return 30;
|
192
|
+
case 13: return 5;
|
193
|
+
default: return 0;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
#define EPOCH_COPTIC 103605
|
198
|
+
#define BEFORE_COPTIC (103605 - 1)
|
199
|
+
|
200
|
+
int
|
201
|
+
coptic_to_rd(int year, int month, int day)
|
202
|
+
{
|
203
|
+
int sumres;
|
204
|
+
|
205
|
+
{
|
206
|
+
int temp, m;
|
207
|
+
for (temp = 0, m = 1;
|
208
|
+
(m < month);
|
209
|
+
temp = temp + coptic_last_day_of_month(year, m), m++)
|
210
|
+
;
|
211
|
+
sumres = temp;
|
212
|
+
}
|
213
|
+
return day
|
214
|
+
+ sumres
|
215
|
+
+ (365 * (year - 1))
|
216
|
+
+ quotient(year, 4)
|
217
|
+
+ BEFORE_COPTIC;
|
218
|
+
}
|
219
|
+
|
220
|
+
void
|
221
|
+
rd_to_coptic(int date, int *ryear, int *rmonth, int *rday)
|
222
|
+
{
|
223
|
+
int approx, month, day, year;
|
224
|
+
int sumres1, sumres2;
|
225
|
+
|
226
|
+
approx = approximate(date - BEFORE_COPTIC, 366);
|
227
|
+
{
|
228
|
+
int temp, y;
|
229
|
+
for (temp = 0, y = approx;
|
230
|
+
(date >= coptic_to_rd(1 + y, 1, 1));
|
231
|
+
temp = temp + 1, y++)
|
232
|
+
;
|
233
|
+
sumres1 = temp;
|
234
|
+
}
|
235
|
+
year = approx
|
236
|
+
+ sumres1;
|
237
|
+
{
|
238
|
+
int temp, m;
|
239
|
+
for (temp = 0, m = 1;
|
240
|
+
(date > coptic_to_rd
|
241
|
+
(year, m, coptic_last_day_of_month(year, m)));
|
242
|
+
temp = temp + 1, m++)
|
243
|
+
;
|
244
|
+
sumres2 = temp;
|
245
|
+
}
|
246
|
+
month = 1
|
247
|
+
+ sumres2;
|
248
|
+
day = date - (coptic_to_rd(year, month, 1) - 1);
|
249
|
+
if (rmonth)
|
250
|
+
*rmonth = month;
|
251
|
+
if (rday)
|
252
|
+
*rday = day;
|
253
|
+
if (ryear)
|
254
|
+
*ryear = year;
|
255
|
+
}
|
256
|
+
|
257
|
+
int
|
258
|
+
ethiopian_leap_year(int year)
|
259
|
+
{
|
260
|
+
return coptic_leap_year(year);
|
261
|
+
}
|
262
|
+
|
263
|
+
int
|
264
|
+
ethiopian_last_day_of_month(int year, int month)
|
265
|
+
{
|
266
|
+
return coptic_last_day_of_month(year, month);
|
267
|
+
}
|
268
|
+
|
269
|
+
#define EPOCH_ETHIOPIAN 2796
|
270
|
+
#define BEFORE_ETHIOPIAN (2796 - 1)
|
271
|
+
|
272
|
+
int
|
273
|
+
ethiopian_to_rd(int year, int month, int day)
|
274
|
+
{
|
275
|
+
return
|
276
|
+
coptic_to_rd(year, month, day) - (EPOCH_COPTIC - EPOCH_ETHIOPIAN);
|
277
|
+
}
|
278
|
+
|
279
|
+
void
|
280
|
+
rd_to_ethiopian(int date, int *ryear, int *rmonth, int *rday)
|
281
|
+
{
|
282
|
+
rd_to_coptic
|
283
|
+
(date + (EPOCH_COPTIC - EPOCH_ETHIOPIAN),
|
284
|
+
ryear, rmonth, rday);
|
285
|
+
}
|
286
|
+
|
287
|
+
int
|
288
|
+
jalali_leap_year(int year)
|
289
|
+
{
|
290
|
+
return mod(29 + (8 * year), 33) < 8;
|
291
|
+
}
|
292
|
+
|
293
|
+
int
|
294
|
+
jalali_last_day_of_month(int year, int month)
|
295
|
+
{
|
296
|
+
if (month == 12 && jalali_leap_year(year))
|
297
|
+
return 30;
|
298
|
+
switch (month) {
|
299
|
+
case 1: return 31;
|
300
|
+
case 2: return 31;
|
301
|
+
case 3: return 31;
|
302
|
+
case 4: return 31;
|
303
|
+
case 5: return 31;
|
304
|
+
case 6: return 31;
|
305
|
+
case 7: return 30;
|
306
|
+
case 8: return 30;
|
307
|
+
case 9: return 30;
|
308
|
+
case 10: return 30;
|
309
|
+
case 11: return 30;
|
310
|
+
case 12: return 29;
|
311
|
+
default: return 0;
|
312
|
+
}
|
313
|
+
}
|
314
|
+
|
315
|
+
#define BEFORE_JALALI (226895 - 1)
|
316
|
+
|
317
|
+
int
|
318
|
+
jalali_to_rd(int year, int month, int day)
|
319
|
+
{
|
320
|
+
int sumres;
|
321
|
+
|
322
|
+
{
|
323
|
+
int temp, m;
|
324
|
+
for (temp = 0, m = 1;
|
325
|
+
(m < month);
|
326
|
+
temp = temp + jalali_last_day_of_month(year, m), m++)
|
327
|
+
;
|
328
|
+
sumres = temp;
|
329
|
+
}
|
330
|
+
return day
|
331
|
+
+ sumres
|
332
|
+
+ (365 * (year - 1))
|
333
|
+
+ quotient(21 + (8 * year), 33)
|
334
|
+
+ BEFORE_JALALI;
|
335
|
+
}
|
336
|
+
|
337
|
+
void
|
338
|
+
rd_to_jalali(int date, int *ryear, int *rmonth, int *rday)
|
339
|
+
{
|
340
|
+
int approx, month, day, year;
|
341
|
+
int sumres1, sumres2;
|
342
|
+
|
343
|
+
approx = approximate(date - BEFORE_JALALI, 366);
|
344
|
+
{
|
345
|
+
int temp, y;
|
346
|
+
for (temp = 0, y = approx;
|
347
|
+
(date >= jalali_to_rd(1 + y, 1, 1));
|
348
|
+
temp = temp + 1, y++)
|
349
|
+
;
|
350
|
+
sumres1 = temp;
|
351
|
+
}
|
352
|
+
year = approx
|
353
|
+
+ sumres1;
|
354
|
+
{
|
355
|
+
int temp, m;
|
356
|
+
for (temp = 0, m = 1;
|
357
|
+
(date > jalali_to_rd
|
358
|
+
(year, m, jalali_last_day_of_month(year, m)));
|
359
|
+
temp = temp + 1, m++)
|
360
|
+
;
|
361
|
+
sumres2 = temp;
|
362
|
+
}
|
363
|
+
month = 1
|
364
|
+
+ sumres2;
|
365
|
+
day = date - (jalali_to_rd(year, month, 1) - 1);
|
366
|
+
if (rmonth)
|
367
|
+
*rmonth = month;
|
368
|
+
if (rday)
|
369
|
+
*rday = day;
|
370
|
+
if (ryear)
|
371
|
+
*ryear = year;
|
372
|
+
}
|
373
|
+
|
374
|
+
int
|
375
|
+
bahai_leap_year(int year)
|
376
|
+
{
|
377
|
+
return gregorian_leap_year(year + 1844);
|
378
|
+
}
|
379
|
+
|
380
|
+
int
|
381
|
+
bahai_last_day_of_month(int year, int month)
|
382
|
+
{
|
383
|
+
if (month == 19) {
|
384
|
+
if (bahai_leap_year(year))
|
385
|
+
return 5;
|
386
|
+
else
|
387
|
+
return 4;
|
388
|
+
}
|
389
|
+
return 19;
|
390
|
+
}
|
391
|
+
|
392
|
+
#define BEFORE_BAHAI (673222 - 1)
|
393
|
+
|
394
|
+
int
|
395
|
+
bahai_to_rd(int year, int month, int day)
|
396
|
+
{
|
397
|
+
int sumres;
|
398
|
+
|
399
|
+
{
|
400
|
+
int temp, m;
|
401
|
+
for (temp = 0, m = 1;
|
402
|
+
(m < month);
|
403
|
+
temp = temp + bahai_last_day_of_month(year, m), m++)
|
404
|
+
;
|
405
|
+
sumres = temp;
|
406
|
+
}
|
407
|
+
return day
|
408
|
+
+ sumres
|
409
|
+
+ gregorian_to_rd(year + 1843, 3, 20);
|
410
|
+
}
|
411
|
+
|
412
|
+
void
|
413
|
+
rd_to_bahai(int date, int *ryear, int *rmonth, int *rday)
|
414
|
+
{
|
415
|
+
int approx, month, day, year;
|
416
|
+
int sumres1, sumres2;
|
417
|
+
|
418
|
+
approx = approximate(date - BEFORE_BAHAI, 366);
|
419
|
+
{
|
420
|
+
int temp, y;
|
421
|
+
for (temp = 0, y = approx;
|
422
|
+
(date >= bahai_to_rd(1 + y, 1, 1));
|
423
|
+
temp = temp + 1, y++)
|
424
|
+
;
|
425
|
+
sumres1 = temp;
|
426
|
+
}
|
427
|
+
year = approx
|
428
|
+
+ sumres1;
|
429
|
+
{
|
430
|
+
int temp, m;
|
431
|
+
for (temp = 0, m = 1;
|
432
|
+
(date > bahai_to_rd
|
433
|
+
(year, m, bahai_last_day_of_month(year, m)));
|
434
|
+
temp = temp + 1, m++)
|
435
|
+
;
|
436
|
+
sumres2 = temp;
|
437
|
+
}
|
438
|
+
month = 1
|
439
|
+
+ sumres2;
|
440
|
+
day = date - (bahai_to_rd(year, month, 1) - 1);
|
441
|
+
if (rmonth)
|
442
|
+
*rmonth = month;
|
443
|
+
if (rday)
|
444
|
+
*rday = day;
|
445
|
+
if (ryear)
|
446
|
+
*ryear = year;
|
447
|
+
}
|
448
|
+
|
449
|
+
void
|
450
|
+
bahai_year_to_vahid(int year, int *rkull, int *rvahid, int *ryear)
|
451
|
+
{
|
452
|
+
int r;
|
453
|
+
*rkull = quotient(year - 1, 361) + 1;
|
454
|
+
r = mod(year - 1, 361);
|
455
|
+
*rvahid = quotient(r, 19) + 1;
|
456
|
+
*ryear = mod(r, 19) + 1;
|
457
|
+
}
|
458
|
+
|
459
|
+
int
|
460
|
+
bahai_vahid_to_year(int kull, int vahid, int year)
|
461
|
+
{
|
462
|
+
return (kull - 1) * 361 + (vahid - 1) * 19 + year;
|
463
|
+
}
|
464
|
+
|
465
|
+
int
|
466
|
+
indian_national_leap_year(int year)
|
467
|
+
{
|
468
|
+
return gregorian_leap_year(year + 78);
|
469
|
+
}
|
470
|
+
|
471
|
+
int
|
472
|
+
indian_national_last_day_of_month(int year, int month)
|
473
|
+
{
|
474
|
+
if (month == 1 && indian_national_leap_year(year))
|
475
|
+
return 31;
|
476
|
+
switch (month) {
|
477
|
+
case 1: return 30;
|
478
|
+
case 2: return 31;
|
479
|
+
case 3: return 31;
|
480
|
+
case 4: return 31;
|
481
|
+
case 5: return 31;
|
482
|
+
case 6: return 31;
|
483
|
+
case 7: return 30;
|
484
|
+
case 8: return 30;
|
485
|
+
case 9: return 30;
|
486
|
+
case 10: return 30;
|
487
|
+
case 11: return 30;
|
488
|
+
case 12: return 30;
|
489
|
+
default: return 0;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
int
|
494
|
+
indian_national_to_rd(int year, int month, int day)
|
495
|
+
{
|
496
|
+
int sumres;
|
497
|
+
|
498
|
+
{
|
499
|
+
int temp, m;
|
500
|
+
for (temp = 0, m = 1;
|
501
|
+
(m < month);
|
502
|
+
temp = temp + indian_national_last_day_of_month(year, m), m++)
|
503
|
+
;
|
504
|
+
sumres = temp;
|
505
|
+
}
|
506
|
+
return day
|
507
|
+
+ sumres
|
508
|
+
+ gregorian_to_rd(year + 78, 1, 1) + 79;
|
509
|
+
}
|
510
|
+
|
511
|
+
#define BEFORE_INDIAN_NATIONAL (28205 - 1)
|
512
|
+
|
513
|
+
void
|
514
|
+
rd_to_indian_national(int date, int *ryear, int *rmonth, int *rday)
|
515
|
+
{
|
516
|
+
int approx, month, day, year;
|
517
|
+
int sumres1, sumres2;
|
518
|
+
|
519
|
+
approx = approximate(date - BEFORE_INDIAN_NATIONAL, 366);
|
520
|
+
{
|
521
|
+
int temp, y;
|
522
|
+
for (temp = -1, y = approx;
|
523
|
+
(date >= indian_national_to_rd(y, 1, 1));
|
524
|
+
temp = temp + 1, y++)
|
525
|
+
;
|
526
|
+
sumres1 = temp;
|
527
|
+
}
|
528
|
+
year = approx
|
529
|
+
+ sumres1;
|
530
|
+
{
|
531
|
+
int temp, m;
|
532
|
+
for (temp = 0, m = 1;
|
533
|
+
(date > indian_national_to_rd
|
534
|
+
(year, m, indian_national_last_day_of_month(year, m)));
|
535
|
+
temp = temp + 1, m++)
|
536
|
+
;
|
537
|
+
sumres2 = temp;
|
538
|
+
}
|
539
|
+
month = 1
|
540
|
+
+ sumres2;
|
541
|
+
day = date - (indian_national_to_rd(year, month, 1) - 1);
|
542
|
+
if (rmonth)
|
543
|
+
*rmonth = month;
|
544
|
+
if (rday)
|
545
|
+
*rday = day;
|
546
|
+
if (ryear)
|
547
|
+
*ryear = year;
|
548
|
+
}
|
549
|
+
|
550
|
+
int
|
551
|
+
bengali_leap_year(int year)
|
552
|
+
{
|
553
|
+
return gregorian_leap_year(year + 594);
|
554
|
+
}
|
555
|
+
|
556
|
+
int
|
557
|
+
bengali_last_day_of_month(int year, int month)
|
558
|
+
{
|
559
|
+
if (month == 11 && bengali_leap_year(year))
|
560
|
+
return 31;
|
561
|
+
switch (month) {
|
562
|
+
case 1: return 31;
|
563
|
+
case 2: return 31;
|
564
|
+
case 3: return 31;
|
565
|
+
case 4: return 31;
|
566
|
+
case 5: return 31;
|
567
|
+
case 6: return 30;
|
568
|
+
case 7: return 30;
|
569
|
+
case 8: return 30;
|
570
|
+
case 9: return 30;
|
571
|
+
case 10: return 30;
|
572
|
+
case 11: return 30;
|
573
|
+
case 12: return 30;
|
574
|
+
default: return 0;
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
int
|
579
|
+
bengali_to_rd(int year, int month, int day)
|
580
|
+
{
|
581
|
+
int sumres;
|
582
|
+
|
583
|
+
{
|
584
|
+
int temp, m;
|
585
|
+
for (temp = 0, m = 1;
|
586
|
+
(m < month);
|
587
|
+
temp = temp + bengali_last_day_of_month(year, m), m++)
|
588
|
+
;
|
589
|
+
sumres = temp;
|
590
|
+
}
|
591
|
+
return day
|
592
|
+
+ sumres
|
593
|
+
+ gregorian_to_rd(year + 593, 4, 13);
|
594
|
+
}
|
595
|
+
|
596
|
+
#define BEFORE_BENGALI (216693 - 1)
|
597
|
+
|
598
|
+
void
|
599
|
+
rd_to_bengali(int date, int *ryear, int *rmonth, int *rday)
|
600
|
+
{
|
601
|
+
int approx, month, day, year;
|
602
|
+
int sumres1, sumres2;
|
603
|
+
|
604
|
+
approx = approximate(date - BEFORE_BENGALI, 366);
|
605
|
+
{
|
606
|
+
int temp, y;
|
607
|
+
for (temp = 0, y = approx;
|
608
|
+
(date >= bengali_to_rd(1 + y, 1, 1));
|
609
|
+
temp = temp + 1, y++)
|
610
|
+
;
|
611
|
+
sumres1 = temp;
|
612
|
+
}
|
613
|
+
year = approx
|
614
|
+
+ sumres1;
|
615
|
+
{
|
616
|
+
int temp, m;
|
617
|
+
for (temp = 0, m = 1;
|
618
|
+
(date > bengali_to_rd
|
619
|
+
(year, m, bengali_last_day_of_month(year, m)));
|
620
|
+
temp = temp + 1, m++)
|
621
|
+
;
|
622
|
+
sumres2 = temp;
|
623
|
+
}
|
624
|
+
month = 1
|
625
|
+
+ sumres2;
|
626
|
+
day = date - (bengali_to_rd(year, month, 1) - 1);
|
627
|
+
if (rmonth)
|
628
|
+
*rmonth = month;
|
629
|
+
if (rday)
|
630
|
+
*rday = day;
|
631
|
+
if (ryear)
|
632
|
+
*ryear = year;
|
633
|
+
}
|
634
|
+
|
635
|
+
int
|
636
|
+
nanakshahi_leap_year(int year)
|
637
|
+
{
|
638
|
+
return gregorian_leap_year(year + 1469);
|
639
|
+
}
|
640
|
+
|
641
|
+
int
|
642
|
+
nanakshahi_last_day_of_month(int year, int month)
|
643
|
+
{
|
644
|
+
if (month == 12 && nanakshahi_leap_year(year))
|
645
|
+
return 31;
|
646
|
+
switch (month) {
|
647
|
+
case 1: return 31;
|
648
|
+
case 2: return 31;
|
649
|
+
case 3: return 31;
|
650
|
+
case 4: return 31;
|
651
|
+
case 5: return 31;
|
652
|
+
case 6: return 30;
|
653
|
+
case 7: return 30;
|
654
|
+
case 8: return 30;
|
655
|
+
case 9: return 30;
|
656
|
+
case 10: return 30;
|
657
|
+
case 11: return 30;
|
658
|
+
case 12: return 30;
|
659
|
+
default: return 0;
|
660
|
+
}
|
661
|
+
}
|
662
|
+
|
663
|
+
int
|
664
|
+
nanakshahi_to_rd(int year, int month, int day)
|
665
|
+
{
|
666
|
+
int sumres;
|
667
|
+
|
668
|
+
{
|
669
|
+
int temp, m;
|
670
|
+
for (temp = 0, m = 1;
|
671
|
+
(m < month);
|
672
|
+
temp = temp + nanakshahi_last_day_of_month(year, m), m++)
|
673
|
+
;
|
674
|
+
sumres = temp;
|
675
|
+
}
|
676
|
+
return day
|
677
|
+
+ sumres
|
678
|
+
+ gregorian_to_rd(year + 1468, 3, 13);
|
679
|
+
}
|
680
|
+
|
681
|
+
#define BEFORE_NANAKSHAHI (536258 - 1)
|
682
|
+
|
683
|
+
void
|
684
|
+
rd_to_nanakshahi(int date, int *ryear, int *rmonth, int *rday)
|
685
|
+
{
|
686
|
+
int approx, month, day, year;
|
687
|
+
int sumres1, sumres2;
|
688
|
+
|
689
|
+
approx = approximate(date - BEFORE_NANAKSHAHI, 366);
|
690
|
+
{
|
691
|
+
int temp, y;
|
692
|
+
for (temp = 0, y = approx;
|
693
|
+
(date >= nanakshahi_to_rd(1 + y, 1, 1));
|
694
|
+
temp = temp + 1, y++)
|
695
|
+
;
|
696
|
+
sumres1 = temp;
|
697
|
+
}
|
698
|
+
year = approx
|
699
|
+
+ sumres1;
|
700
|
+
{
|
701
|
+
int temp, m;
|
702
|
+
for (temp = 0, m = 1;
|
703
|
+
(date > nanakshahi_to_rd
|
704
|
+
(year, m, nanakshahi_last_day_of_month(year, m)));
|
705
|
+
temp = temp + 1, m++)
|
706
|
+
;
|
707
|
+
sumres2 = temp;
|
708
|
+
}
|
709
|
+
month = 1
|
710
|
+
+ sumres2;
|
711
|
+
day = date - (nanakshahi_to_rd(year, month, 1) - 1);
|
712
|
+
if (rmonth)
|
713
|
+
*rmonth = month;
|
714
|
+
if (rday)
|
715
|
+
*rday = day;
|
716
|
+
if (ryear)
|
717
|
+
*ryear = year;
|
718
|
+
}
|
719
|
+
|
720
|
+
#ifndef PLUTO
|
721
|
+
int
|
722
|
+
ordinal_to_rd(int year, int day)
|
723
|
+
{
|
724
|
+
return gregorian_to_rd(year, 1, 1) + day - 1;
|
725
|
+
}
|
726
|
+
|
727
|
+
void
|
728
|
+
rd_to_ordinal(int date, int *ryear, int *rday)
|
729
|
+
{
|
730
|
+
int month, day, year, date2;
|
731
|
+
|
732
|
+
rd_to_gregorian(date, &year, &month, &day);
|
733
|
+
date2 = gregorian_to_rd(year, 1, 1);
|
734
|
+
if (rday)
|
735
|
+
*rday = date - date2 + 1;
|
736
|
+
if (ryear)
|
737
|
+
*ryear = year;
|
738
|
+
}
|
739
|
+
#endif
|
740
|
+
|
741
|
+
int
|
742
|
+
jd_to_rd(int date) /* chronological */
|
743
|
+
{
|
744
|
+
return date - 1721425;
|
745
|
+
}
|
746
|
+
|
747
|
+
int
|
748
|
+
rd_to_jd(int date) /* chronological */
|
749
|
+
{
|
750
|
+
return date + 1721425;
|
751
|
+
}
|
752
|
+
|
753
|
+
#ifndef PLUTO
|
754
|
+
int
|
755
|
+
mjd_to_rd(int date) /* chronological */
|
756
|
+
{
|
757
|
+
return date + 678576;
|
758
|
+
}
|
759
|
+
|
760
|
+
int
|
761
|
+
rd_to_mjd(int date) /* chronological */
|
762
|
+
{
|
763
|
+
return date - 678576;
|
764
|
+
}
|
765
|
+
|
766
|
+
int
|
767
|
+
mjd_to_jd(int date) /* chronological */
|
768
|
+
{
|
769
|
+
return date + 2400001;
|
770
|
+
}
|
771
|
+
|
772
|
+
int
|
773
|
+
jd_to_mjd(int date) /* chronological */
|
774
|
+
{
|
775
|
+
return date - 2400001;
|
776
|
+
}
|
777
|
+
|
778
|
+
int
|
779
|
+
ld_to_rd(int date)
|
780
|
+
{
|
781
|
+
return date + 577735;
|
782
|
+
}
|
783
|
+
|
784
|
+
int
|
785
|
+
rd_to_ld(int date)
|
786
|
+
{
|
787
|
+
return date - 577735;
|
788
|
+
}
|
789
|
+
|
790
|
+
int
|
791
|
+
rd_to_day_of_week(int date)
|
792
|
+
{
|
793
|
+
return mod(date, 7);
|
794
|
+
}
|
795
|
+
#endif /* not PLUTO */
|
796
|
+
|
797
|
+
|
798
|
+
/*
|
799
|
+
Local Variables:
|
800
|
+
c-basic-offset: 2
|
801
|
+
End:
|
802
|
+
*/
|