14 #include RUBY_EXTCONF_H
24 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
26 #define f_abs(x) rb_funcall(x, rb_intern("abs"), 0)
27 #define f_negate(x) rb_funcall(x, rb_intern("-@"), 0)
28 #define f_add(x,y) rb_funcall(x, '+', 1, y)
29 #define f_sub(x,y) rb_funcall(x, '-', 1, y)
30 #define f_mul(x,y) rb_funcall(x, '*', 1, y)
31 #define f_div(x,y) rb_funcall(x, '/', 1, y)
32 #define f_quo(x,y) rb_funcall(x, rb_intern("quo"), 1, y)
33 #define f_idiv(x,y) rb_funcall(x, rb_intern("div"), 1, y)
34 #define f_mod(x,y) rb_funcall(x, '%', 1, y)
35 #define f_remainder(x,y) rb_funcall(x, rb_intern("remainder"), 1, y)
36 #define f_expt(x,y) rb_funcall(x, rb_intern("**"), 1, y)
37 #define f_floor(x) rb_funcall(x, rb_intern("floor"), 0)
38 #define f_ceil(x) rb_funcall(x, rb_intern("ceil"), 0)
39 #define f_truncate(x) rb_funcall(x, rb_intern("truncate"), 0)
40 #define f_round(x) rb_funcall(x, rb_intern("round"), 0)
42 #define f_to_i(x) rb_funcall(x, rb_intern("to_i"), 0)
43 #define f_to_r(x) rb_funcall(x, rb_intern("to_r"), 0)
44 #define f_to_s(x) rb_funcall(x, rb_intern("to_s"), 0)
45 #define f_inspect(x) rb_funcall(x, rb_intern("inspect"), 0)
47 #define f_add3(x,y,z) f_add(f_add(x, y), z)
48 #define f_sub3(x,y,z) f_sub(f_sub(x, y), z)
121 #define f_nonzero_p(x) (!f_zero_p(x))
131 #define f_positive_p(x) (!f_negative_p(x))
133 #define f_ajd(x) rb_funcall(x, rb_intern("ajd"), 0)
134 #define f_jd(x) rb_funcall(x, rb_intern("jd"), 0)
135 #define f_year(x) rb_funcall(x, rb_intern("year"), 0)
136 #define f_mon(x) rb_funcall(x, rb_intern("mon"), 0)
137 #define f_mday(x) rb_funcall(x, rb_intern("mday"), 0)
138 #define f_wday(x) rb_funcall(x, rb_intern("wday"), 0)
139 #define f_hour(x) rb_funcall(x, rb_intern("hour"), 0)
140 #define f_min(x) rb_funcall(x, rb_intern("min"), 0)
141 #define f_sec(x) rb_funcall(x, rb_intern("sec"), 0)
144 #define NDIV(x,y) (-(-((x)+1)/(y))-1)
145 #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
146 #define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d))
147 #define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d))
149 #define HAVE_JD (1 << 0)
150 #define HAVE_DF (1 << 1)
151 #define HAVE_CIVIL (1 << 2)
152 #define HAVE_TIME (1 << 3)
153 #define COMPLEX_DAT (1 << 7)
155 #define have_jd_p(x) ((x)->flags & HAVE_JD)
156 #define have_df_p(x) ((x)->flags & HAVE_DF)
157 #define have_civil_p(x) ((x)->flags & HAVE_CIVIL)
158 #define have_time_p(x) ((x)->flags & HAVE_TIME)
159 #define complex_dat_p(x) ((x)->flags & COMPLEX_DAT)
160 #define simple_dat_p(x) (!complex_dat_p(x))
162 #define ITALY 2299161
163 #define ENGLAND 2361222
164 #define JULIAN positive_inf
165 #define GREGORIAN negative_inf
166 #define DEFAULT_SG ITALY
168 #define UNIX_EPOCH_IN_CJD INT2FIX(2440588)
170 #define MINUTE_IN_SECONDS 60
171 #define HOUR_IN_SECONDS 3600
172 #define DAY_IN_SECONDS 86400
173 #define SECOND_IN_MILLISECONDS 1000
174 #define SECOND_IN_NANOSECONDS 1000000000
176 #define JC_PERIOD0 1461
177 #define GC_PERIOD0 146097
178 #define CM_PERIOD0 71149239
179 #define CM_PERIOD (0xfffffff / CM_PERIOD0 * CM_PERIOD0)
180 #define CM_PERIOD_JCY (CM_PERIOD / JC_PERIOD0 * 4)
181 #define CM_PERIOD_GCY (CM_PERIOD / GC_PERIOD0 * 400)
183 #define REFORM_BEGIN_YEAR 1582
184 #define REFORM_END_YEAR 1930
185 #define REFORM_BEGIN_JD 2298874
186 #define REFORM_END_JD 2426355
196 #define MIN_SHIFT SEC_WIDTH
197 #define HOUR_SHIFT (MIN_WIDTH + SEC_WIDTH)
198 #define MDAY_SHIFT (HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
199 #define MON_SHIFT (MDAY_WIDTH + HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
201 #define PK_MASK(x) ((1 << (x)) - 1)
203 #define EX_SEC(x) (((x) >> SEC_SHIFT) & PK_MASK(SEC_WIDTH))
204 #define EX_MIN(x) (((x) >> MIN_SHIFT) & PK_MASK(MIN_WIDTH))
205 #define EX_HOUR(x) (((x) >> HOUR_SHIFT) & PK_MASK(HOUR_WIDTH))
206 #define EX_MDAY(x) (((x) >> MDAY_SHIFT) & PK_MASK(MDAY_WIDTH))
207 #define EX_MON(x) (((x) >> MON_SHIFT) & PK_MASK(MON_WIDTH))
209 #define PACK5(m,d,h,min,s) \
210 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT) |\
211 ((h) << HOUR_SHIFT) | ((min) << MIN_SHIFT) | ((s) << SEC_SHIFT))
214 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT))
221 #if defined(FLT_RADIX) && defined(FLT_MANT_DIG) && FLT_RADIX == 2 && FLT_MANT_DIG > 22
222 #define date_sg_t float
224 #define date_sg_t double
285 union DateData *dat;\
286 Data_Get_Struct(x, union DateData, dat);
289 union DateData *adat;\
290 Data_Get_Struct(x, union DateData, adat);
293 union DateData *bdat;\
294 Data_Get_Struct(x, union DateData, bdat);
297 union DateData *adat, *bdat;\
298 Data_Get_Struct(x, union DateData, adat);\
299 Data_Get_Struct(y, union DateData, bdat);
313 #define set_to_simple(x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
315 (x)->nth = canon(_nth);\
317 (x)->sg = (date_sg_t)(_sg);\
321 (x)->flags = _flags;\
324 #define set_to_simple(x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
326 (x)->nth = canon(_nth);\
328 (x)->sg = (date_sg_t)(_sg);\
330 (x)->pc = PACK2(_mon, _mday);\
331 (x)->flags = _flags;\
336 #define set_to_complex(x, _nth, _jd ,_df, _sf, _of, _sg,\
337 _year, _mon, _mday, _hour, _min, _sec, _flags) \
339 (x)->nth = canon(_nth);\
342 (x)->sf = canon(_sf);\
344 (x)->sg = (date_sg_t)(_sg);\
351 (x)->flags = _flags;\
354 #define set_to_complex(x, _nth, _jd ,_df, _sf, _of, _sg,\
355 _year, _mon, _mday, _hour, _min, _sec, _flags) \
357 (x)->nth = canon(_nth);\
360 (x)->sf = canon(_sf);\
362 (x)->sg = (date_sg_t)(_sg);\
364 (x)->pc = PACK5(_mon, _mday, _hour, _min, _sec);\
365 (x)->flags = _flags;\
370 #define copy_simple_to_complex(x, y) \
372 (x)->nth = (y)->nth;\
375 (x)->sf = INT2FIX(0);\
377 (x)->sg = (date_sg_t)((y)->sg);\
378 (x)->year = (y)->year;\
379 (x)->mon = (y)->mon;\
380 (x)->mday = (y)->mday;\
384 (x)->flags = (y)->flags;\
387 #define copy_simple_to_complex(x, y) \
389 (x)->nth = (y)->nth;\
392 (x)->sf = INT2FIX(0);\
394 (x)->sg = (date_sg_t)((y)->sg);\
395 (x)->year = (y)->year;\
396 (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
397 (x)->flags = (y)->flags;\
402 #define copy_complex_to_simple(x, y) \
404 (x)->nth = (y)->nth;\
406 (x)->sg = (date_sg_t)((y)->sg);\
407 (x)->year = (y)->year;\
408 (x)->mon = (y)->mon;\
409 (x)->mday = (y)->mday;\
410 (x)->flags = (y)->flags;\
413 #define copy_complex_to_simple(x, y) \
415 (x)->nth = (y)->nth;\
417 (x)->sg = (date_sg_t)((y)->sg);\
418 (x)->year = (y)->year;\
419 (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
420 (x)->flags = (y)->flags;\
427 int *,
int *,
int *,
int *);
434 for (d = 1; d < 31; d++)
445 for (i = 0; i < 30; i++)
453 c_find_fdom(
int y,
int m,
double sg,
int *rjd,
int *ns)
457 for (d = 1; d < 31; d++)
469 for (i = 0; i < 30; i++)
484 a = floor(y / 100.0);
485 b = 2 - a + floor(a / 4.0);
486 jd = floor(365.25 * (y + 4716)) +
487 floor(30.6001 * (m + 1)) +
502 double x, a, b, c, d, e, y, m, dom;
507 x = floor((jd - 1867216.25) / 36524.25);
508 a = jd + 1 + x - floor(x / 4.0);
511 c = floor((b - 122.1) / 365.25);
512 d = floor(365.25 * c);
513 e = floor((b - d) / 30.6001);
514 dom = b - d - floor(30.6001 * e);
536 *ns = (*rjd <
sg) ? 0 : 1;
542 int rm2, rd2, rjd, ns;
546 *rd = (jd - rjd) + 1;
557 (rjd2 -
MOD((rjd2 - 1) + 1, 7)) +
560 *ns = (*rjd <
sg) ? 0 : 1;
566 int ry2, rm2, rd2, a, rjd2, ns2;
577 *rw = 1 +
DIV(jd - rjd2, 7);
578 *rd =
MOD(jd + 1, 7);
590 *rjd = (rjd2 -
MOD(((rjd2 - f) + 1), 7) - 7) + 7 * w + d;
591 *ns = (*rjd <
sg) ? 0 : 1;
597 int rm, rd2, rjd, ns, j;
602 j = jd - (rjd -
MOD((rjd - f) + 1, 7)) + 7;
603 *rw = (int)
DIV(j, 7);
604 *rd = (int)
MOD(j, 7);
609 c_nth_kday_to_jd(
int y,
int m,
int n,
int k,
double sg,
int *rjd,
int *ns)
614 c_find_fdom(y, m, sg, &rjd2, &ns2);
621 *rjd = (rjd2 -
MOD((rjd2 - k) + 1, 7)) + 7 * n;
622 *ns = (*rjd <
sg) ? 0 : 1;
629 return MOD(jd + 1, 7);
634 c_jd_to_nth_kday(
int jd,
double sg,
int *ry,
int *rm,
int *rn,
int *rk)
639 c_find_fdom(*ry, *rm, sg, &rjd, &ns2);
640 *rn =
DIV(jd - rjd, 7) + 1;
647 int *rd,
int *rjd,
int *ns)
663 if (ry2 != y || rd2 != d)
669 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
670 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
676 return MOD(y, 4) == 0;
682 return MOD(y, 4) == 0 && y % 100 != 0 ||
MOD(y, 400) == 0;
688 assert(m >= 1 && m <= 12);
695 assert(m >= 1 && m <= 12);
711 if (d < 1 || d > last)
730 if (d < 1 || d > last)
739 int *rm,
int *rd,
int *rjd,
int *ns)
749 if (ry != y || *rm != m)
755 if (ry != y || *rm != m || *rd != d)
762 int *rw,
int *rd,
int *rjd,
int *ns)
764 int ns2, ry2, rw2, rd2;
779 if (y != ry2 || w != *rw || d != *rd)
786 int *rw,
int *rd,
int *rjd,
int *ns)
788 int ns2, ry2, rw2, rd2;
803 if (y != ry2 || w != *rw || d != *rd)
810 c_valid_nth_kday_p(
int y,
int m,
int n,
int k,
double sg,
811 int *rm,
int *rn,
int *rk,
int *rjd,
int *ns)
813 int ns2, ry2, rm2, rn2, rk2;
824 c_nth_kday_to_jd(ny, nm, 1, k, sg, &rjd2, &ns2);
825 c_jd_to_nth_kday(rjd2 + n * 7, sg, &ry2, &rm2, &rn2, &rk2);
826 if (ry2 != y || rm2 != m)
830 c_nth_kday_to_jd(y, m, n, k, sg, rjd, ns);
831 c_jd_to_nth_kday(*rjd, sg, &ry2, rm, rn, rk);
832 if (y != ry2 || m != *rm || n != *rn || k != *rk)
850 return !(h < 0 || h > 24 ||
851 min < 0 || min > 59 ||
853 (h == 24 && (min > 0 || s > 0)));
1074 inline static double
1086 inline static double
1098 inline static double
1107 #define canonicalize_jd(_nth, _jd) \
1110 _nth = f_sub(_nth, INT2FIX(1));\
1113 if (_jd >= CM_PERIOD) {\
1114 _nth = f_add(_nth, INT2FIX(1));\
1200 int r, m, d, h, min, s;
1263 int jd, y, m, d, h, min, s;
1308 period = (style < 0) ?
1318 inth =
DIV(it, ((
long)period));
1321 it =
MOD(it, ((
long)period));
1322 *ry = (int)it - 4712;
1340 period = (style < 0) ?
1375 inline static double
1505 m_local_df_in_day(
union DateData *x)
1552 #define HALF_DAYS_IN_SECONDS (DAY_IN_SECONDS / 2)
1632 inline static double
1676 if (
isinf(sg) && sg > 0)
1687 if (
isinf(sg) && sg < 0)
1783 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
1784 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
1790 assert(m >= 1 && m <= 12);
1797 assert(m >= 1 && m <= 12);
1941 #define decode_offset(of,s,h,m)\
1944 s = (of < 0) ? '-' : '+';\
1945 a = (of < 0) ? -of : of;\
1946 h = a / HOUR_IN_SECONDS;\
1947 m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
1999 civil_to_jd(
VALUE y,
int m,
int d,
double sg,
2025 jd_to_civil(
VALUE jd,
double sg,
2026 VALUE *nth,
int *rjd,
2027 int *ry,
int *rm,
int *rd)
2034 ordinal_to_jd(
VALUE y,
int d,
double sg,
2035 VALUE *nth,
int *ry,
2060 jd_to_ordinal(
VALUE jd,
double sg,
2061 VALUE *nth,
int *rjd,
2069 commercial_to_jd(
VALUE y,
int w,
int d,
double sg,
2070 VALUE *nth,
int *ry,
2095 jd_to_commercial(
VALUE jd,
double sg,
2096 VALUE *nth,
int *rjd,
2097 int *ry,
int *rw,
int *rd)
2104 weeknum_to_jd(
VALUE y,
int w,
int d,
int f,
double sg,
2105 VALUE *nth,
int *ry,
2130 jd_to_weeknum(
VALUE jd,
int f,
double sg,
2131 VALUE *nth,
int *rjd,
2132 int *ry,
int *rw,
int *rd)
2139 nth_kday_to_jd(
VALUE y,
int m,
int n,
int k,
double sg,
2140 VALUE *nth,
int *ry,
2149 c_nth_kday_to_jd(
FIX2INT(y), m, n, k, sg, &jd, ns);
2160 c_nth_kday_to_jd(*ry, m, n, k, style, rjd, ns);
2165 jd_to_nth_kday(
VALUE jd,
double sg,
2166 VALUE *nth,
int *rjd,
2167 int *ry,
int *rm,
int *rn,
int *rk)
2170 c_jd_to_nth_kday(*rjd, sg, ry, rm, rn, rk);
2176 VALUE *nth,
int *ry,
2206 VALUE *nth,
int *ry,
2215 VALUE *nth,
int *ry,
2216 int *rm,
int *rd,
int *rjd,
2251 VALUE *nth,
int *ry,
2252 int *rw,
int *rd,
int *rjd,
2281 VALUE *nth,
int *ry,
2282 int *rw,
int *rd,
int *rjd,
2311 valid_nth_kday_p(
VALUE y,
int m,
int n,
int k,
double sg,
2312 VALUE *nth,
int *ry,
2313 int *rm,
int *rn,
int *rk,
int *rjd,
2322 r = c_valid_nth_kday_p(
FIX2INT(y), m, n, k, sg, rm, rn, rk, &jd, ns);
2335 r = c_valid_nth_kday_p(*ry, m, n, k, style, rm, rn, rk, rjd, ns);
2346 switch (
TYPE(vof)) {
2352 if (n != -1 && n != 0 && n != 1)
2364 *rof = (int)
round(n);
2373 #ifdef CANONICALIZATION_FOR_MATHN
2385 #ifdef CANONICALIZATION_FOR_MATHN
2433 #define valid_sg(sg) \
2435 if (!c_valid_start_p(sg)) {\
2437 rb_warning("invalid start is ignored");\
2501 int m, d, ry, rm, rd;
2536 date_s__valid_civil_p(
int argc,
VALUE *argv,
VALUE klass)
2538 VALUE vy, vm, vd, vsg;
2570 VALUE vy, vm, vd, vsg;
2619 date_s__valid_ordinal_p(
int argc,
VALUE *argv,
VALUE klass)
2672 int w, d, ry, rw, rd;
2700 date_s__valid_commercial_p(
int argc,
VALUE *argv,
VALUE klass)
2702 VALUE vy, vw, vd, vsg;
2733 VALUE vy, vw, vd, vsg;
2753 valid_weeknum_sub(
int argc,
VALUE *argv,
VALUE klass,
int need_jd)
2756 int w, d,
f, ry, rw, rd;
2784 date_s__valid_weeknum_p(
int argc,
VALUE *argv,
VALUE klass)
2786 VALUE vy, vw, vd, vf, vsg;
2789 rb_scan_args(argc, argv,
"41", &vy, &vw, &vd, &vf, &vsg);
2800 return valid_weeknum_sub(5, argv2, klass, 1);
2804 date_s_valid_weeknum_p(
int argc,
VALUE *argv,
VALUE klass)
2806 VALUE vy, vw, vd, vf, vsg;
2809 rb_scan_args(argc, argv,
"41", &vy, &vw, &vd, &vf, &vsg);
2820 if (
NIL_P(valid_weeknum_sub(5, argv2, klass, 0)))
2826 valid_nth_kday_sub(
int argc,
VALUE *argv,
VALUE klass,
int need_jd)
2829 int m, n, k, ry, rm, rn, rk;
2842 if (!valid_nth_kday_p(y, m, n, k, sg,
2844 &rm, &rn, &rk, &rjd,
2855 date_s__valid_nth_kday_p(
int argc,
VALUE *argv,
VALUE klass)
2857 VALUE vy, vm, vn, vk, vsg;
2860 rb_scan_args(argc, argv,
"41", &vy, &vm, &vn, &vk, &vsg);
2871 return valid_nth_kday_sub(5, argv2, klass, 1);
2875 date_s_valid_nth_kday_p(
int argc,
VALUE *argv,
VALUE klass)
2877 VALUE vy, vm, vn, vk, vsg;
2880 rb_scan_args(argc, argv,
"41", &vy, &vm, &vn, &vk, &vsg);
2891 if (
NIL_P(valid_nth_kday_sub(5, argv2, klass, 0)))
2960 int y,
int m,
int d,
2980 int y,
int m,
int d,
2981 int h,
int min,
int s,
3029 int *rof,
double *rsg)
3067 date_s_new_bang(
int argc,
VALUE *argv,
VALUE klass)
3085 &nth, &jd, &df, &sf, &rof, &rsg);
3115 return round(d) == d;
3152 #define jd_trunc d_trunc
3153 #define k_trunc d_trunc
3206 #define num2num_with_frac(s,n) \
3208 s = s##_trunc(v##s, &fr);\
3209 if (f_nonzero_p(fr)) {\
3211 rb_raise(rb_eArgError, "invalid fraction");\
3216 #define num2int_with_frac(s,n) \
3218 s = NUM2INT(s##_trunc(v##s, &fr));\
3219 if (f_nonzero_p(fr)) {\
3221 rb_raise(rb_eArgError, "invalid fraction");\
3226 #define canon24oc() \
3230 fr2 = f_add(fr2, INT2FIX(1));\
3234 #define add_frac() \
3236 if (f_nonzero_p(fr2))\
3237 ret = d_lite_plus(ret, fr2);\
3240 #define val2sg(vsg,dsg) \
3242 dsg = NUM2DBL(vsg);\
3243 if (!c_valid_start_p(dsg)) {\
3245 rb_warning("invalid start is ignored");\
3267 VALUE vjd, vsg,
jd, fr, fr2, ret;
3317 VALUE vy, vd, vsg, y, fr, fr2, ret;
3339 int ry, rd, rjd, ns;
3385 VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
3425 int ry, rm, rd, rjd, ns;
3462 VALUE vy, vw, vd, vsg, y, fr, fr2, ret;
3487 int ry, rw, rd, rjd, ns;
3507 date_s_weeknum(
int argc,
VALUE *argv,
VALUE klass)
3509 VALUE vy, vw, vd, vf, vsg, y, fr, fr2, ret;
3513 rb_scan_args(argc, argv,
"05", &vy, &vw, &vd, &vf, &vsg);
3537 int ry, rw, rd, rjd, ns;
3556 date_s_nth_kday(
int argc,
VALUE *argv,
VALUE klass)
3558 VALUE vy, vm, vn, vk, vsg, y, fr, fr2, ret;
3562 rb_scan_args(argc, argv,
"05", &vy, &vm, &vn, &vk, &vsg);
3586 int ry, rm, rn, rk, rjd, ns;
3588 if (!valid_nth_kday_p(y, m, n, k, sg,
3590 &rm, &rn, &rk, &rjd,
3605 #if !defined(HAVE_GMTIME_R)
3609 auto struct tm *tmp = gmtime(t);
3618 auto struct tm *tmp = localtime(t);
3638 VALUE vsg, nth, ret;
3657 y = tm.tm_year + 1900;
3675 #define set_hash0(k,v) rb_hash_aset(hash, k, v)
3676 #define ref_hash0(k) rb_hash_aref(hash, k)
3677 #define del_hash0(k) rb_hash_delete(hash, k)
3679 #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
3680 #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
3681 #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
3689 if (!
NIL_P(seconds)) {
3690 VALUE d, h, min, s, fr;
3715 #define sym(x) ID2SYM(rb_intern(x))
3822 int i, eno = 0, idx = 0;
3855 if (k ==
sym(
"ordinal")) {
3864 else if (k ==
sym(
"civil")) {
3881 else if (k ==
sym(
"commercial")) {
3898 else if (k ==
sym(
"wday")) {
3905 else if (k ==
sym(
"wnum0")) {
3922 else if (k ==
sym(
"wnum1")) {
3941 if (g && k ==
sym(
"time")) {
3972 int ry, rd, rjd, ns;
3987 int ry, rm, rd, rjd, ns;
4002 int ry, rw, rd, rjd, ns;
4017 int ry, rw, rd, rjd, ns;
4053 VALUE year, mon, mday;
4065 VALUE year, week, wday;
4085 VALUE year, week, wday;
4105 VALUE year, week, wday;
4168 const char *fmt,
size_t flen,
VALUE hash);
4172 const char *default_fmt)
4175 const char *str, *fmt;
4183 "string should have ASCII compatible encoding");
4188 flen =
strlen(default_fmt);
4194 "format should have ASCII compatible encoding");
4295 "string should have ASCII compatible encoding");
4352 VALUE str, comp, sg;
4540 str =
rb_str_new2(
"Mon, 1 Jan -4712 00:00:00 +0000");
4582 str =
rb_str_new2(
"Mon, 01 Jan -4712 00:00:00 GMT");
4681 #define val2off(vof,iof) \
4683 if (!offset_to_sec(vof, &iof)) {\
4685 rb_warning("invalid offset is ignored");\
4691 d_lite_initialize(
int argc,
VALUE *argv,
VALUE self)
4693 VALUE jd, vjd, vdf, sf, vsf, vof, vsg;
4700 rb_scan_args(argc, argv,
"05", &vjd, &vdf, &vsf, &vof, &vsg);
4739 "cannot load complex into simple");
4767 "cannot load complex into simple");
4778 d_lite_fill(
VALUE self)
5008 d_lite_wnum0(
VALUE self)
5015 d_lite_wnum1(
VALUE self)
5285 int rjd, ns, ry, rm, rd;
5506 switch (
TYPE(other)) {
5523 jd =
m_jd(dat) + (int)t;
5537 dat->c.df, dat->c.sf,
5538 dat->c.of, dat->c.sg,
5576 jd =
m_jd(dat) + jd;
5595 dat->c.df, dat->c.sf,
5596 dat->c.of, dat->c.sg,
5669 df =
m_df(dat) + df;
5683 jd =
m_jd(dat) + jd;
5716 #ifdef CANONICALIZATION_FOR_MATHN
5772 df =
m_df(dat) + df;
5786 jd =
m_jd(dat) + jd;
5892 switch (
TYPE(other)) {
5967 VALUE t, y, nth, rjd2;
5994 &rm, &rd, &rjd, &ns))
6104 VALUE limit, step, date;
6211 a_nth =
m_nth(adat);
6212 b_nth =
m_nth(bdat);
6225 else if (
f_lt_p(a_sf, b_sf)) {
6232 else if (a_df < b_df) {
6239 else if (a_jd < b_jd) {
6246 else if (
f_lt_p(a_nth, b_nth)) {
6282 return cmp_dd(
self, other);
6291 a_nth =
m_nth(adat);
6292 b_nth =
m_nth(bdat);
6299 else if (a_jd < b_jd) {
6306 else if (
f_lt_p(a_nth, b_nth)) {
6327 a_nth =
m_nth(adat);
6328 b_nth =
m_nth(bdat);
6332 if (a_year == b_year) {
6334 a_mon =
m_mon(adat);
6335 b_mon =
m_mon(bdat);
6336 if (a_mon == b_mon) {
6339 if (a_mday == b_mday) {
6342 else if (a_mday < b_mday) {
6349 else if (a_mon < b_mon) {
6361 else if (a_pd < b_pd) {
6369 else if (a_year < b_year) {
6376 else if (
f_lt_p(a_nth, b_nth)) {
6434 a_nth =
m_nth(adat);
6435 b_nth =
m_nth(bdat);
6457 a_nth =
m_nth(adat);
6458 b_nth =
m_nth(bdat);
6462 if (a_year == b_year) {
6464 a_mon =
m_mon(adat);
6465 b_mon =
m_mon(bdat);
6466 if (a_mon == b_mon) {
6469 if (a_mday == b_mday)
6533 mk_inspect_flags(
union DateData *x)
6545 mk_inspect_raw(
union DateData *x,
const char *klass)
6555 "(%sth,%dj),+0s,%.0fj; "
6557 klass ? klass :
"?",
6560 x->
s.
year, x->
s.mon, x->
s.mday,
6568 VALUE nth, sf, flags;
6576 "(%sth,%dj,%ds,%sn),%+ds,%.0fj; "
6577 "%dy%dm%dd %dh%dm%ds; %s>",
6578 klass ? klass :
"?",
6583 x->
c.
year, x->
c.mon, x->
c.mday,
6584 x->
c.hour, x->
c.min, x->
c.sec,
6596 d_lite_inspect_raw(
VALUE self)
6612 "#<%s: %s ((%sj,%ds,%sn),%+ds,%.0fj)>",
6613 klass ? klass :
"?",
6645 size_t date_strftime(
char *s,
size_t maxsize,
const char *format,
6648 #define SMALLBUF 100
6653 size_t size, len, flen;
6662 if (len != 0 || (**buf ==
'\0' &&
errno != ERANGE))
return len;
6663 for (size=1024; ; size*=2) {
6676 if (size >= 1024 * flen) {
6700 #define MILLISECOND_IN_NANOSECONDS 1000000
6731 (int (*)(
void *))
m_mon,
6740 (int (*)(
void *))
m_min,
6741 (int (*)(
void *))
m_sec,
6753 tmx->
dat = (
void *)dat;
6759 const char *default_fmt,
6777 "format should have ASCII compatible encoding");
6782 (*func)(
self, &tmx);
6783 if (memchr(fmt,
'\0', len)) {
6785 const char *
p = fmt, *pe = fmt + len;
6792 if (buf != buffer) {
6796 for (fmt = p; p < pe && !*
p; ++
p);
6807 if (buf != buffer)
xfree(buf);
7005 (*func)(
self, &tmx);
7008 if (buf != buffer)
xfree(buf);
7127 d_lite_marshal_dump_old(
VALUE self)
7187 VALUE ajd, of, sg, nth, sf;
7206 &nth, &jd, &df, &sf, &rof, &rsg);
7213 "cannot load complex into simple");
7238 "cannot load complex into simple");
7287 VALUE vjd, vh, vmin, vs, vof, vsg, jd, fr, fr2, ret;
7291 rb_scan_args(argc, argv,
"06", &vjd, &vh, &vmin, &vs, &vof, &vsg);
7317 int rh, rmin, rs, rjd, rjd2;
7355 VALUE vy, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7356 int d, h, min, s, rof;
7359 rb_scan_args(argc, argv,
"07", &vy, &vd, &vh, &vmin, &vs, &vof, &vsg);
7388 int ry, rd, rh, rmin, rs, rjd, rjd2, ns;
7431 VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7432 int m, d, h, min, s, rof;
7435 rb_scan_args(argc, argv,
"08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
7467 int ry, rm, rd, rh, rmin, rs;
7487 int ry, rm, rd, rh, rmin, rs, rjd, rjd2, ns;
7528 VALUE vy, vw, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7529 int w, d, h, min, s, rof;
7532 rb_scan_args(argc, argv,
"08", &vy, &vw, &vd, &vh, &vmin, &vs, &vof, &vsg);
7564 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7593 datetime_s_weeknum(
int argc,
VALUE *argv,
VALUE klass)
7595 VALUE vy, vw, vd, vf, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7596 int w, d,
f, h, min, s, rof;
7600 &vh, &vmin, &vs, &vof, &vsg);
7635 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7662 datetime_s_nth_kday(
int argc,
VALUE *argv,
VALUE klass)
7664 VALUE vy, vm, vn, vk, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7665 int m, n, k, h, min, s, rof;
7669 &vh, &vmin, &vs, &vof, &vsg);
7704 int ry, rm, rn, rk, rh, rmin, rs, rjd, rjd2, ns;
7706 if (!valid_nth_kday_p(y, m, n, k, sg,
7708 &rm, &rn, &rk, &rjd,
7742 VALUE vsg, nth, ret;
7744 #ifdef HAVE_CLOCK_GETTIME
7752 int y, ry, m, d, h, min, s;
7761 #ifdef HAVE_CLOCK_GETTIME
7762 if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
7774 y = tm.tm_year + 1900;
7782 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
7784 #elif defined(HAVE_VAR_TIMEZONE)
7785 #ifdef HAVE_VAR_ALTZONE
7786 of = (long)-((tm.tm_isdst > 0) ? altzone :
timezone);
7794 of += (long)difftime(sec2, sec);
7797 #elif defined(HAVE_TIMEGM)
7802 of = (long)difftime(sec2, sec);
7811 tm2.tm_isdst = tm.tm_isdst;
7812 sec2 = mktime(&tm2);
7813 of = (long)difftime(sec, sec2);
7816 #ifdef HAVE_CLOCK_GETTIME
8019 VALUE str, comp, sg;
8156 str =
rb_str_new2(
"Mon, 1 Jan -4712 00:00:00 +0000");
8186 str =
rb_str_new2(
"Mon, 01 Jan -4712 00:00:00 GMT");
8424 "%Y-%m-%dT%H:%M:%S%:z",
set_tmx);
8522 #define f_getlocal(x) rb_funcall(x, rb_intern("getlocal"), 0)
8523 #define f_subsec(x) rb_funcall(x, rb_intern("subsec"), 0)
8524 #define f_utc_offset(x) rb_funcall(x, rb_intern("utc_offset"), 0)
8525 #define f_local3(x,y,m,d) rb_funcall(x, rb_intern("local"), 3, y, m, d)
8526 #define f_utc6(x,y,m,d,h,min,s) rb_funcall(x, rb_intern("utc"), 6,\
8580 VALUE y, sf, nth, ret;
8581 int ry, m, d, h, min, s, of;
8755 #define MIN_YEAR -4713
8756 #define MAX_YEAR 1000000
8758 #define MAX_JD 366963925
8761 test_civil(
int from,
int to,
double sg)
8765 fprintf(stderr,
"test_civil: %d...%d (%d) - %.0f\n",
8766 from, to, to - from, sg);
8767 for (j = from; j <= to; j++) {
8768 int y, m, d, rj, ns;
8773 fprintf(stderr,
"%d != %d\n", j, rj);
8781 date_s_test_civil(
VALUE klass)
8783 if (!test_civil(MIN_JD, MIN_JD + 366,
GREGORIAN))
8785 if (!test_civil(2305814, 2598007,
GREGORIAN))
8787 if (!test_civil(MAX_JD - 366, MAX_JD,
GREGORIAN))
8790 if (!test_civil(MIN_JD, MIN_JD + 366,
ITALY))
8792 if (!test_civil(2305814, 2598007,
ITALY))
8794 if (!test_civil(MAX_JD - 366, MAX_JD,
ITALY))
8801 test_ordinal(
int from,
int to,
double sg)
8805 fprintf(stderr,
"test_ordinal: %d...%d (%d) - %.0f\n",
8806 from, to, to - from, sg);
8807 for (j = from; j <= to; j++) {
8813 fprintf(stderr,
"%d != %d\n", j, rj);
8821 date_s_test_ordinal(
VALUE klass)
8823 if (!test_ordinal(MIN_JD, MIN_JD + 366,
GREGORIAN))
8825 if (!test_ordinal(2305814, 2598007,
GREGORIAN))
8827 if (!test_ordinal(MAX_JD - 366, MAX_JD,
GREGORIAN))
8830 if (!test_ordinal(MIN_JD, MIN_JD + 366,
ITALY))
8832 if (!test_ordinal(2305814, 2598007,
ITALY))
8834 if (!test_ordinal(MAX_JD - 366, MAX_JD,
ITALY))
8841 test_commercial(
int from,
int to,
double sg)
8845 fprintf(stderr,
"test_commercial: %d...%d (%d) - %.0f\n",
8846 from, to, to - from, sg);
8847 for (j = from; j <= to; j++) {
8848 int y, w, d, rj, ns;
8853 fprintf(stderr,
"%d != %d\n", j, rj);
8861 date_s_test_commercial(
VALUE klass)
8863 if (!test_commercial(MIN_JD, MIN_JD + 366,
GREGORIAN))
8865 if (!test_commercial(2305814, 2598007,
GREGORIAN))
8867 if (!test_commercial(MAX_JD - 366, MAX_JD,
GREGORIAN))
8870 if (!test_commercial(MIN_JD, MIN_JD + 366,
ITALY))
8872 if (!test_commercial(2305814, 2598007,
ITALY))
8874 if (!test_commercial(MAX_JD - 366, MAX_JD,
ITALY))
8881 test_weeknum(
int from,
int to,
int f,
double sg)
8885 fprintf(stderr,
"test_weeknum: %d...%d (%d) - %.0f\n",
8886 from, to, to - from, sg);
8887 for (j = from; j <= to; j++) {
8888 int y, w, d, rj, ns;
8893 fprintf(stderr,
"%d != %d\n", j, rj);
8901 date_s_test_weeknum(
VALUE klass)
8905 for (f = 0; f <= 1; f++) {
8906 if (!test_weeknum(MIN_JD, MIN_JD + 366, f,
GREGORIAN))
8908 if (!test_weeknum(2305814, 2598007, f,
GREGORIAN))
8910 if (!test_weeknum(MAX_JD - 366, MAX_JD, f,
GREGORIAN))
8913 if (!test_weeknum(MIN_JD, MIN_JD + 366, f,
ITALY))
8915 if (!test_weeknum(2305814, 2598007, f,
ITALY))
8917 if (!test_weeknum(MAX_JD - 366, MAX_JD, f,
ITALY))
8925 test_nth_kday(
int from,
int to,
double sg)
8929 fprintf(stderr,
"test_nth_kday: %d...%d (%d) - %.0f\n",
8930 from, to, to - from, sg);
8931 for (j = from; j <= to; j++) {
8932 int y, m, n, k, rj, ns;
8934 c_jd_to_nth_kday(j, sg, &y, &m, &n, &k);
8935 c_nth_kday_to_jd(y, m, n, k, sg, &rj, &ns);
8937 fprintf(stderr,
"%d != %d\n", j, rj);
8945 date_s_test_nth_kday(
VALUE klass)
8947 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
GREGORIAN))
8949 if (!test_nth_kday(2305814, 2598007,
GREGORIAN))
8951 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
GREGORIAN))
8954 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
ITALY))
8956 if (!test_nth_kday(2305814, 2598007,
ITALY))
8958 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
ITALY))
8979 if (!test_unit_v2v(
INT2FIX(0), conv1, conv2))
8981 if (!test_unit_v2v(
INT2FIX(1), conv1, conv2))
8983 if (!test_unit_v2v(
INT2FIX(2), conv1, conv2))
8985 if (!test_unit_v2v(
INT2FIX(3), conv1, conv2))
8987 if (!test_unit_v2v(
INT2FIX(11), conv1, conv2))
8989 if (!test_unit_v2v(
INT2FIX(65535), conv1, conv2))
8991 if (!test_unit_v2v(
INT2FIX(1073741823), conv1, conv2))
8993 if (!test_unit_v2v(
INT2NUM(1073741824), conv1, conv2))
9010 if (!test_unit_v2v_iter2(conv1, conv2))
9012 if (!test_unit_v2v_iter2(conv2, conv1))
9018 date_s_test_unit_conv(
VALUE klass)
9022 if (!test_unit_v2v_iter(ms_to_sec,
sec_to_ms))
9024 if (!test_unit_v2v_iter(
ns_to_day, day_to_ns))
9032 date_s_test_all(
VALUE klass)
9034 if (date_s_test_civil(klass) ==
Qfalse)
9036 if (date_s_test_ordinal(klass) ==
Qfalse)
9038 if (date_s_test_commercial(klass) ==
Qfalse)
9040 if (date_s_test_weeknum(klass) ==
Qfalse)
9042 if (date_s_test_nth_kday(klass) ==
Qfalse)
9044 if (date_s_test_unit_conv(klass) ==
Qfalse)
9052 "January",
"February",
"March",
9053 "April",
"May",
"June",
9054 "July",
"August",
"September",
9055 "October",
"November",
"December"
9060 "Jan",
"Feb",
"Mar",
"Apr",
9061 "May",
"Jun",
"Jul",
"Aug",
9062 "Sep",
"Oct",
"Nov",
"Dec"
9066 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
9067 "Thursday",
"Friday",
"Saturday"
9071 "Sun",
"Mon",
"Tue",
"Wed",
9082 for (i = 0; i < len; i++) {
9101 #define rb_intern(str) rb_intern_const(str)
9103 assert(fprintf(stderr,
"assert() is now active\n"));
9112 #if (LONG_MAX / DAY_IN_SECONDS) > SECOND_IN_NANOSECONDS
9115 #elif defined HAVE_LONG_LONG
9117 SECOND_IN_NANOSECONDS);
9120 INT2FIX(SECOND_IN_NANOSECONDS));
9377 #define de_define_private_method rb_define_private_method
9379 date_s__valid_jd_p, -1);
9380 de_define_private_method(
CLASS_OF(
cDate),
"_valid_ordinal?",
9381 date_s__valid_ordinal_p, -1);
9383 date_s__valid_civil_p, -1);
9385 date_s__valid_civil_p, -1);
9386 de_define_private_method(
CLASS_OF(
cDate),
"_valid_commercial?",
9387 date_s__valid_commercial_p, -1);
9388 de_define_private_method(
CLASS_OF(
cDate),
"_valid_weeknum?",
9389 date_s__valid_weeknum_p, -1);
9390 de_define_private_method(
CLASS_OF(
cDate),
"_valid_nth_kday?",
9391 date_s__valid_nth_kday_p, -1);
9404 date_s_valid_weeknum_p, -1);
9405 de_define_private_method(
CLASS_OF(
cDate),
"valid_nth_kday?",
9406 date_s_valid_nth_kday_p, -1);
9408 date_s_zone_to_diff, 1);
9418 #define de_define_singleton_method rb_define_singleton_method
9419 #define de_define_alias rb_define_alias
9420 de_define_singleton_method(
cDate,
"new!", date_s_new_bang, -1);
9431 de_define_singleton_method(
cDate,
"weeknum", date_s_weeknum, -1);
9432 de_define_singleton_method(
cDate,
"nth_kday", date_s_nth_kday, -1);
9456 #define de_define_method rb_define_method
9457 de_define_method(
cDate,
"initialize", d_lite_initialize, -1);
9462 de_define_method(
cDate,
"fill", d_lite_fill, 0);
9484 de_define_private_method(
cDate,
"wnum0", d_lite_wnum0, 0);
9485 de_define_private_method(
cDate,
"wnum1", d_lite_wnum1, 0);
9499 de_define_method(
cDate,
"nth_kday?", d_lite_nth_kday_p, 2);
9552 de_define_method(
cDate,
"inspect_raw", d_lite_inspect_raw, 0);
9569 de_define_method(
cDate,
"marshal_dump_old", d_lite_marshal_dump_old, 0);
9587 de_define_singleton_method(
cDateTime,
"weeknum",
9588 datetime_s_weeknum, -1);
9589 de_define_singleton_method(
cDateTime,
"nth_kday",
9590 datetime_s_nth_kday, -1);
9617 #define f_public(m,s) rb_funcall(m, rb_intern("public"), 1,\
9618 ID2SYM(rb_intern(s)))
9657 de_define_singleton_method(
cDate,
"test_civil", date_s_test_civil, 0);
9658 de_define_singleton_method(
cDate,
"test_ordinal", date_s_test_ordinal, 0);
9659 de_define_singleton_method(
cDate,
"test_commercial",
9660 date_s_test_commercial, 0);
9661 de_define_singleton_method(
cDate,
"test_weeknum", date_s_test_weeknum, 0);
9662 de_define_singleton_method(
cDate,
"test_nth_kday", date_s_test_nth_kday, 0);
9663 de_define_singleton_method(
cDate,
"test_unit_conv",
9664 date_s_test_unit_conv, 0);
9665 de_define_singleton_method(
cDate,
"test_all", date_s_test_all, 0);
static VALUE d_lite_gregorian_p(VALUE self)
static VALUE date_s__rfc3339(VALUE klass, VALUE str)
static VALUE m_of_in_day(union DateData *x)
static VALUE datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
static VALUE datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
static VALUE date_s__load(VALUE klass, VALUE s)
static VALUE d_lite_strftime(int argc, VALUE *argv, VALUE self)
static VALUE datetime_s__strptime(int argc, VALUE *argv, VALUE klass)
static int c_julian_last_day_of_month(int y, int m)
static VALUE day_in_nanoseconds
static VALUE strftimev(const char *, VALUE, void(*)(VALUE, struct tmx *))
#define rb_rational_new2(x, y)
static VALUE d_lite_minus(VALUE self, VALUE other)
static VALUE d_lite_initialize_copy(VALUE copy, VALUE date)
static VALUE k_numeric_p(VALUE x)
static VALUE datetime_s_jd(int argc, VALUE *argv, VALUE klass)
static int m_proleptic_julian_p(union DateData *x)
static VALUE d_lite_amjd(VALUE self)
static VALUE d_lite_sec_fraction(VALUE self)
static VALUE tmx_m_secs(union DateData *x)
int gettimeofday(struct timeval *, struct timezone *)
static VALUE half_days_in_day
static VALUE day_to_sec(VALUE d)
void rb_enc_copy(VALUE obj1, VALUE obj2)
static VALUE m_zone(union DateData *x)
static VALUE date_to_date(VALUE self)
static VALUE m_real_local_jd(union DateData *x)
size_t strlen(const char *)
static VALUE date_s__httpdate(VALUE klass, VALUE str)
static VALUE d_lite_cwday(VALUE self)
static VALUE k_rational_p(VALUE x)
static VALUE d_lite_leap_p(VALUE self)
static VALUE m_real_jd(union DateData *x)
#define canonicalize_jd(_nth, _jd)
static int max(int a, int b)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static int m_julian_p(union DateData *x)
static VALUE rt__valid_weeknum_p(VALUE y, VALUE w, VALUE d, VALUE f, VALUE sg)
static int c_valid_civil_p(int, int, int, double, int *, int *, int *, int *)
static VALUE d_lite_jd(VALUE)
VALUE rb_f_sprintf(int, const VALUE *)
static VALUE datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
#define PACK5(m, d, h, min, s)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE to_integer(VALUE x)
static VALUE d_lite_offset(VALUE self)
static VALUE d_lite_tuesday_p(VALUE self)
static int c_julian_leap_p(int y)
static const char * abbr_monthnames[]
static VALUE d_lite_next(VALUE self)
static VALUE d_lite_upto(VALUE self, VALUE max)
static VALUE datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
static void get_c_jd(union DateData *x)
static int c_find_ldom(int y, int m, double sg, int *rjd, int *ns)
static int m_min(union DateData *x)
static VALUE date_s_httpdate(int argc, VALUE *argv, VALUE klass)
static VALUE d_lite_equal(VALUE self, VALUE other)
static int m_wnum1(union DateData *x)
static VALUE f_ge_p(VALUE x, VALUE y)
static VALUE equal_gen(VALUE self, VALUE other)
static VALUE d_lite_lshift(VALUE self, VALUE other)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static int m_hour(union DateData *x)
static VALUE d_lite_mon(VALUE self)
static VALUE date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
static VALUE date_s_iso8601(int argc, VALUE *argv, VALUE klass)
static VALUE dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
static double s_virtual_sg(union DateData *x)
static VALUE jisx0301_date(VALUE jd, VALUE y)
static VALUE d_lite_s_alloc_complex(VALUE klass)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE rt__valid_commercial_p(VALUE y, VALUE w, VALUE d, VALUE sg)
static VALUE d_lite_new_offset(int argc, VALUE *argv, VALUE self)
st_index_t rb_memhash(const void *ptr, long len)
static VALUE dt_lite_strftime(int argc, VALUE *argv, VALUE self)
#define rb_check_trusted(obj)
static VALUE d_lite_cmp(VALUE, VALUE)
static VALUE f_kind_of_p(VALUE x, VALUE c)
#define decode_offset(of, s, h, m)
static struct tm * localtime_r(const time_t *t, struct tm *tm)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static double m_virtual_sg(union DateData *x)
void rb_raise(VALUE exc, const char *fmt,...)
static void decode_day(VALUE d, VALUE *jd, VALUE *df, VALUE *sf)
static int m_wnumx(union DateData *x, int f)
static VALUE datetime_to_time(VALUE self)
static void set_tmx(VALUE, struct tmx *)
static VALUE d_lite_downto(VALUE self, VALUE min)
static VALUE d_lite_httpdate(VALUE self)
static int m_year(union DateData *x)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
#define set_to_complex(x, _nth, _jd,_df, _sf, _of, _sg, _year, _mon, _mday, _hour, _min, _sec, _flags)
static void set_of(union DateData *x, int of)
static VALUE m_ajd(union DateData *x)
VALUE rb_ary_new3(long n,...)
static VALUE date_s_civil(int argc, VALUE *argv, VALUE klass)
static int tmx_m_of(union DateData *x)
static int m_of(union DateData *x)
static VALUE d_lite_iso8601(VALUE self)
static VALUE d_lite_start(VALUE self)
void rb_include_module(VALUE klass, VALUE module)
VALUE date__rfc3339(VALUE)
void rb_gc_mark(VALUE ptr)
static VALUE date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
static int c_jd_to_wday(int jd)
static void encode_jd(VALUE nth, int jd, VALUE *rjd)
static int jd_utc_to_local(int jd, int df, int of)
static int m_mon(union DateData *x)
static VALUE f_zero_p(VALUE x)
static VALUE date_s_ordinal(int argc, VALUE *argv, VALUE klass)
static VALUE sec_to_ms(VALUE s)
static VALUE d_lite_italy(VALUE self)
static VALUE f_negative_p(VALUE x)
static void get_s_civil(union DateData *x)
size_t date_strftime(char *s, size_t maxsize, const char *format, const struct tmx *tmx)
static VALUE valid_ordinal_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
static int valid_civil_p(VALUE y, int m, int d, double sg, VALUE *nth, int *ry, int *rm, int *rd, int *rjd, int *ns)
static struct tm * gmtime_r(const time_t *t, struct tm *tm)
void rb_undef_method(VALUE klass, const char *name)
static int time_to_df(int h, int min, int s)
static VALUE of2str(int of)
static VALUE d_lite_rshift(VALUE self, VALUE other)
static VALUE k_datetime_p(VALUE x)
const char * rb_obj_classname(VALUE)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
VALUE date__jisx0301(VALUE)
#define SECOND_IN_MILLISECONDS
static VALUE date_s_julian_leap_p(VALUE klass, VALUE y)
static VALUE d_lite_cwyear(VALUE self)
static VALUE dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
static VALUE d_lite_marshal_dump(VALUE self)
static VALUE h_trunc(VALUE h, VALUE *fr)
static VALUE d_lite_cweek(VALUE self)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
static VALUE date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
#define REFORM_BEGIN_YEAR
static VALUE d_simple_new_internal(VALUE klass, VALUE nth, int jd, double sg, int y, int m, int d, unsigned flags)
#define RB_TYPE_P(obj, type)
static VALUE datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
static int wholenum_p(VALUE x)
static void c_commercial_to_jd(int y, int w, int d, double sg, int *rjd, int *ns)
static int m_proleptic_gregorian_p(union DateData *x)
static int c_valid_gregorian_p(int y, int m, int d, int *rm, int *rd)
static void get_c_time(union DateData *x)
static VALUE d_lite_ld(VALUE self)
static VALUE d_lite_gregorian(VALUE self)
static int local_df(union DateData *x)
void Init_date_core(void)
static VALUE date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
static VALUE m_sf_in_sec(union DateData *x)
static VALUE d_lite_prev_day(int argc, VALUE *argv, VALUE self)
static VALUE d_lite_julian(VALUE self)
static VALUE d_lite_asctime(VALUE self)
static size_t date_strftime_alloc(char **buf, const char *format, struct tmx *tmx)
static int m_local_df(union DateData *x)
static VALUE rt_complete_frags(VALUE klass, VALUE hash)
static VALUE cmp_gen(VALUE self, VALUE other)
static VALUE d_lite_year(VALUE)
static int m_jd(union DateData *x)
static VALUE d_trunc(VALUE d, VALUE *fr)
static VALUE date_s_gregorian_leap_p(VALUE klass, VALUE y)
static VALUE dt_lite_rfc3339(int argc, VALUE *argv, VALUE self)
RUBY_EXTERN VALUE rb_cObject
static VALUE f_le_p(VALUE x, VALUE y)
static double m_sg(union DateData *x)
static int c_valid_commercial_p(int y, int w, int d, double sg, int *rw, int *rd, int *rjd, int *ns)
static VALUE datetime_to_date(VALUE self)
static VALUE date_s__rfc2822(VALUE klass, VALUE str)
static void encode_year(VALUE nth, int y, double style, VALUE *ry)
static const int monthtab[2][13]
static double negative_inf
static const int yeartab[2][13]
static VALUE d_lite_wednesday_p(VALUE self)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static int local_jd(union DateData *x)
static int m_local_jd(union DateData *x)
void rb_define_const(VALUE, const char *, VALUE)
#define num2int_with_frac(s, n)
static int valid_commercial_p(VALUE y, int w, int d, double sg, VALUE *nth, int *ry, int *rw, int *rd, int *rjd, int *ns)
static VALUE d_lite_mday(VALUE self)
static VALUE date_s__strptime_internal(int argc, VALUE *argv, VALUE klass, const char *default_fmt)
static int m_yday(union DateData *x)
#define f_utc6(x, y, m, d, h, min, s)
static void canonicalize_s_jd(union DateData *x)
static VALUE s_trunc(VALUE s, VALUE *fr)
static VALUE f_cmp(VALUE x, VALUE y)
static void c_ordinal_to_jd(int y, int d, double sg, int *rjd, int *ns)
static VALUE d_lite_new_start(int argc, VALUE *argv, VALUE self)
static VALUE f_lt_p(VALUE x, VALUE y)
static int valid_weeknum_p(VALUE y, int w, int d, int f, double sg, VALUE *nth, int *ry, int *rw, int *rd, int *rjd, int *ns)
static VALUE date_s_parse(int argc, VALUE *argv, VALUE klass)
static int c_gregorian_leap_p(int y)
static void m_canonicalize_jd(union DateData *x)
static void c_jd_to_weeknum(int jd, int f, double sg, int *ry, int *rw, int *rd)
void rb_gc_register_mark_object(VALUE obj)
VALUE date__parse(VALUE str, VALUE comp)
RUBY_EXTERN int isinf(double)
static VALUE date_strftime_internal(int argc, VALUE *argv, VALUE self, const char *default_fmt, void(*func)(VALUE, struct tmx *))
static VALUE m_real_cwyear(union DateData *x)
static void c_jd_to_commercial(int jd, double sg, int *ry, int *rw, int *rd)
static int c_julian_to_yday(int y, int m, int d)
static VALUE datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
#define rb_rational_new1(x)
static VALUE d_lite_marshal_load(VALUE self, VALUE a)
static VALUE min_trunc(VALUE min, VALUE *fr)
static void c_weeknum_to_jd(int y, int w, int d, int f, double sg, int *rjd, int *ns)
static void decode_year(VALUE y, double style, VALUE *nth, int *ry)
static VALUE date_s__jisx0301(VALUE klass, VALUE str)
static VALUE sec_to_day(VALUE s)
static VALUE d_lite_next_month(int argc, VALUE *argv, VALUE self)
static VALUE d_lite_step(int argc, VALUE *argv, VALUE self)
#define HALF_DAYS_IN_SECONDS
SSL_METHOD *(* func)(void)
static VALUE time_to_date(VALUE self)
static VALUE isec_to_day(int s)
static int m_df(union DateData *x)
static void c_jd_to_civil(int jd, double sg, int *ry, int *rm, int *rdom)
static VALUE div_day(VALUE d, VALUE *f)
static VALUE m_amjd(union DateData *x)
static VALUE d_lite_thursday_p(VALUE self)
static void get_c_df(union DateData *x)
static VALUE d_lite_inspect(VALUE self)
static VALUE datetime_to_datetime(VALUE self)
VALUE date__iso8601(VALUE)
static VALUE d_lite_next_day(int argc, VALUE *argv, VALUE self)
static VALUE d_lite_day_fraction(VALUE self)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE mk_ary_of_str(long len, const char *a[])
unsigned char buf[MIME_BUF_SIZE]
rb_encoding * rb_usascii_encoding(void)
static void decode_jd(VALUE jd, VALUE *nth, int *rjd)
static VALUE date_s__strptime(int argc, VALUE *argv, VALUE klass)
static VALUE d_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
static VALUE d_lite_next_year(int argc, VALUE *argv, VALUE self)
static VALUE datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
static VALUE d_lite_julian_p(VALUE self)
#define copy_simple_to_complex(x, y)
static VALUE tmx_m_msecs(union DateData *x)
static VALUE time_to_time(VALUE self)
#define rb_enc_str_asciicompat_p(str)
static VALUE rt_rewrite_frags(VALUE hash)
static VALUE dup_obj_with_new_offset(VALUE obj, int of)
static int m_mday(union DateData *x)
static VALUE d_lite_s_alloc_simple(VALUE klass)
static VALUE rt__valid_date_frags_p(VALUE hash, VALUE sg)
static void canonicalize_c_jd(union DateData *x)
static void get_c_civil(union DateData *x)
static VALUE dup_obj_as_complex(VALUE self)
static VALUE datetime_s_parse(int argc, VALUE *argv, VALUE klass)
#define RARRAY_LENINT(ary)
static VALUE dup_obj(VALUE self)
static VALUE time_to_datetime(VALUE self)
RUBY_EXTERN VALUE rb_cNumeric
void rb_sys_fail(const char *mesg)
static VALUE cmp_dd(VALUE self, VALUE other)
static VALUE dup_obj_with_new_start(VALUE obj, double sg)
static VALUE k_date_p(VALUE x)
static int m_wday(union DateData *x)
static VALUE rt__valid_jd_p(VALUE jd, VALUE sg)
static VALUE iso8601_timediv(VALUE self, VALUE n)
#define Data_Make_Struct(klass, type, mark, free, sval)
static VALUE rt__valid_civil_p(VALUE y, VALUE m, VALUE d, VALUE sg)
static VALUE datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
static VALUE mk_inspect(union DateData *x, const char *klass, const char *to_s)
static int c_gregorian_to_yday(int y, int m, int d)
static int m_cwday(union DateData *x)
static void c_jd_to_ordinal(int jd, double sg, int *ry, int *rd)
#define f_local3(x, y, m, d)
static VALUE d_lite_eql_p(VALUE self, VALUE other)
static VALUE date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
static VALUE datetime_s_now(int argc, VALUE *argv, VALUE klass)
VALUE rb_usascii_str_new2(const char *)
static VALUE date_s_strptime(int argc, VALUE *argv, VALUE klass)
static VALUE div_df(VALUE d, VALUE *f)
static void df_to_time(int df, int *h, int *min, int *s)
static struct tmx_funcs tmx_funcs
static VALUE date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
static VALUE m_sf(union DateData *x)
static int m_wnum0(union DateData *x)
static VALUE date_s_commercial(int argc, VALUE *argv, VALUE klass)
RUBY_EXTERN double round(double)
static VALUE d_lite_monday_p(VALUE self)
static VALUE date_to_time(VALUE self)
static int m_sec(union DateData *x)
static VALUE d_lite_friday_p(VALUE self)
static int c_find_ldoy(int y, double sg, int *rjd, int *ns)
static VALUE m_fr(union DateData *x)
static void get_s_jd(union DateData *x)
static VALUE date_s__parse(int argc, VALUE *argv, VALUE klass)
#define val2off(vof, iof)
static VALUE d_lite_sec(VALUE self)
static int m_cweek(union DateData *x)
static char * tmx_m_zone(union DateData *x)
static int safe_mul_p(VALUE x, long m)
static VALUE d_lite_yday(VALUE self)
static VALUE minus_dd(VALUE self, VALUE other)
static int jd_local_to_utc(int jd, int df, int of)
static VALUE d_lite_prev_year(int argc, VALUE *argv, VALUE self)
static const char * abbr_daynames[]
static VALUE f_eqeq_p(VALUE x, VALUE y)
static VALUE valid_civil_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
static void clear_civil(union DateData *x)
VALUE date__httpdate(VALUE)
VALUE rb_marshal_load(VALUE)
static unsigned int hash(const char *str, unsigned int len)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define SECOND_IN_NANOSECONDS
VALUE rb_ary_new2(long capa)
static VALUE date_s_jd(int argc, VALUE *argv, VALUE klass)
static VALUE m_real_year(union DateData *x)
static VALUE d_lite_england(VALUE self)
static VALUE d_lite_saturday_p(VALUE self)
static VALUE d_lite_hash(VALUE self)
static int df_local_to_utc(int df, int of)
static VALUE valid_jd_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
#define MILLISECOND_IN_NANOSECONDS
RUBY_EXTERN VALUE rb_cRational
static int c_valid_weeknum_p(int y, int w, int d, int f, double sg, int *rw, int *rd, int *rjd, int *ns)
#define assert(condition)
static VALUE d_lite_to_s(VALUE self)
static VALUE sec_to_ns(VALUE s)
static VALUE d_lite_plus(VALUE, VALUE)
static double c_virtual_sg(union DateData *x)
static VALUE date_to_datetime(VALUE self)
static VALUE canon(VALUE x)
static int m_gregorian_p(union DateData *x)
static VALUE dt_lite_iso8601(int argc, VALUE *argv, VALUE self)
static VALUE date_s__iso8601(VALUE klass, VALUE str)
static VALUE rt__valid_ordinal_p(VALUE y, VALUE d, VALUE sg)
static const char * monthnames[]
static VALUE date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
VALUE date__rfc2822(VALUE)
static const char * daynames[]
void rb_warning(const char *fmt,...)
static VALUE d_lite_jisx0301(VALUE self)
static VALUE date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
static int c_valid_start_p(double sg)
#define rb_check_frozen(obj)
static VALUE f_gt_p(VALUE x, VALUE y)
static double positive_inf
static VALUE date_s__xmlschema(VALUE klass, VALUE str)
VALUE rb_obj_freeze(VALUE)
static VALUE datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
void rb_copy_generic_ivar(VALUE, VALUE)
static int c_valid_ordinal_p(int y, int d, double sg, int *rd, int *rjd, int *ns)
static int m_pc(union DateData *x)
VALUE date__xmlschema(VALUE)
#define copy_complex_to_simple(x, y)
#define set_to_simple(x, _nth, _jd,_sg, _year, _mon, _mday, _flags)
static int offset_to_sec(VALUE vof, int *rof)
static VALUE date_s_today(int argc, VALUE *argv, VALUE klass)
static int c_gregorian_last_day_of_month(int y, int m)
static VALUE valid_commercial_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
static VALUE m_nth(union DateData *x)
static VALUE d_lite_mjd(VALUE self)
static int valid_ordinal_p(VALUE y, int d, double sg, VALUE *nth, int *ry, int *rd, int *rjd, int *ns)
static VALUE d_lite_rfc2822(VALUE self)
VALUE rb_usascii_str_new(const char *, long)
static VALUE d_lite_s_alloc(VALUE klass)
VALUE date__strptime(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
static VALUE dt_lite_to_s(VALUE self)
static void set_sg(union DateData *, double)
static VALUE d_lite_min(VALUE self)
RUBY_EXTERN VALUE rb_cTime
static VALUE d_complex_new_internal(VALUE klass, VALUE nth, int jd, int df, VALUE sf, int of, double sg, int y, int m, int d, int h, int min, int s, unsigned flags)
static double guess_style(VALUE y, double sg)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define MINUTE_IN_SECONDS
VALUE rb_str_append(VALUE, VALUE)
static int m_cwyear(union DateData *x)
VALUE rb_str_new2(const char *)
VALUE date_zone_to_diff(VALUE)
#define num2num_with_frac(s, n)
static VALUE ns_to_day(VALUE n)
static VALUE d_lite_prev_month(int argc, VALUE *argv, VALUE self)
#define UNIX_EPOCH_IN_CJD
static VALUE datetime_s_civil(int argc, VALUE *argv, VALUE klass)
static VALUE d_lite_hour(VALUE self)
static int c_valid_time_p(int h, int min, int s, int *rh, int *rmin, int *rs)
static VALUE d_lite_wday(VALUE)
static VALUE date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
static int c_valid_julian_p(int y, int m, int d, int *rm, int *rd)
static VALUE d_lite_zone(VALUE self)
static void c_civil_to_jd(int y, int m, int d, double sg, int *rjd, int *ns)
static VALUE d_lite_sunday_p(VALUE self)
static int df_utc_to_local(int df, int of)
static void d_lite_gc_mark(union DateData *dat)
static VALUE d_lite_rfc3339(VALUE self)
static VALUE ns_to_sec(VALUE n)
VALUE rb_num_coerce_cmp(VALUE, VALUE, ID)
static VALUE d_lite_ajd(VALUE self)
static void old_to_new(VALUE ajd, VALUE of, VALUE sg, VALUE *rnth, int *rjd, int *rdf, VALUE *rsf, int *rof, double *rsg)
static int valid_gregorian_p(VALUE y, int m, int d, VALUE *nth, int *ry, int *rm, int *rd)
VALUE rb_str_new(const char *, long)
VALUE rb_obj_class(VALUE)
static int c_find_fdoy(int y, double sg, int *rjd, int *ns)