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;
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
1276 period = (style < 0) ?
1286 inth =
DIV(it, ((
long)period));
1289 it =
MOD(it, ((
long)period));
1290 *ry = (
int)it - 4712;
1308 period = (style < 0) ?
1343 inline static double
1460 m_local_df_in_day(
union DateData *x)
1507 #define HALF_DAYS_IN_SECONDS (DAY_IN_SECONDS / 2)
1587 inline static double
1631 if (
isinf(sg) && sg > 0)
1642 if (
isinf(sg) && sg < 0)
1738 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
1739 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
1745 assert(m >= 1 && m <= 12);
1752 assert(m >= 1 && m <= 12);
1896 #define decode_offset(of,s,h,m)\
1899 s = (of < 0) ? '-' : '+';\
1900 a = (of < 0) ? -of : of;\
1901 h = a / HOUR_IN_SECONDS;\
1902 m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
1954 civil_to_jd(
VALUE y,
int m,
int d,
double sg,
1980 jd_to_civil(
VALUE jd,
double sg,
1981 VALUE *nth,
int *rjd,
1982 int *ry,
int *rm,
int *rd)
1989 ordinal_to_jd(
VALUE y,
int d,
double sg,
1990 VALUE *nth,
int *ry,
2015 jd_to_ordinal(
VALUE jd,
double sg,
2016 VALUE *nth,
int *rjd,
2024 commercial_to_jd(
VALUE y,
int w,
int d,
double sg,
2025 VALUE *nth,
int *ry,
2050 jd_to_commercial(
VALUE jd,
double sg,
2051 VALUE *nth,
int *rjd,
2052 int *ry,
int *rw,
int *rd)
2059 weeknum_to_jd(
VALUE y,
int w,
int d,
int f,
double sg,
2060 VALUE *nth,
int *ry,
2085 jd_to_weeknum(
VALUE jd,
int f,
double sg,
2086 VALUE *nth,
int *rjd,
2087 int *ry,
int *rw,
int *rd)
2094 nth_kday_to_jd(
VALUE y,
int m,
int n,
int k,
double sg,
2095 VALUE *nth,
int *ry,
2104 c_nth_kday_to_jd(
FIX2INT(y), m, n, k, sg, &jd, ns);
2115 c_nth_kday_to_jd(*ry, m, n, k, style, rjd, ns);
2120 jd_to_nth_kday(
VALUE jd,
double sg,
2121 VALUE *nth,
int *rjd,
2122 int *ry,
int *rm,
int *rn,
int *rk)
2125 c_jd_to_nth_kday(*rjd, sg, ry, rm, rn, rk);
2131 VALUE *nth,
int *ry,
2161 VALUE *nth,
int *ry,
2170 VALUE *nth,
int *ry,
2171 int *rm,
int *rd,
int *rjd,
2206 VALUE *nth,
int *ry,
2207 int *rw,
int *rd,
int *rjd,
2236 VALUE *nth,
int *ry,
2237 int *rw,
int *rd,
int *rjd,
2266 valid_nth_kday_p(
VALUE y,
int m,
int n,
int k,
double sg,
2267 VALUE *nth,
int *ry,
2268 int *rm,
int *rn,
int *rk,
int *rjd,
2277 r = c_valid_nth_kday_p(
FIX2INT(y), m, n, k, sg, rm, rn, rk, &jd, ns);
2290 r = c_valid_nth_kday_p(*ry, m, n, k, style, rm, rn, rk, rjd, ns);
2301 switch (
TYPE(vof)) {
2307 if (n != -1 && n != 0 && n != 1)
2328 #ifdef CANONICALIZATION_FOR_MATHN
2340 #ifdef CANONICALIZATION_FOR_MATHN
2388 #define valid_sg(sg) \
2390 if (!c_valid_start_p(sg)) {\
2392 rb_warning("invalid start is ignored");\
2456 int m,
d, ry, rm, rd;
2491 date_s__valid_civil_p(
int argc,
VALUE *argv,
VALUE klass)
2493 VALUE vy, vm, vd, vsg;
2525 VALUE vy, vm, vd, vsg;
2574 date_s__valid_ordinal_p(
int argc,
VALUE *argv,
VALUE klass)
2627 int w,
d, ry, rw, rd;
2655 date_s__valid_commercial_p(
int argc,
VALUE *argv,
VALUE klass)
2657 VALUE vy, vw, vd, vsg;
2688 VALUE vy, vw, vd, vsg;
2708 valid_weeknum_sub(
int argc,
VALUE *argv,
VALUE klass,
int need_jd)
2711 int w,
d,
f, ry, rw, rd;
2739 date_s__valid_weeknum_p(
int argc,
VALUE *argv,
VALUE klass)
2741 VALUE vy, vw, vd, vf, vsg;
2744 rb_scan_args(argc, argv,
"41", &vy, &vw, &vd, &vf, &vsg);
2755 return valid_weeknum_sub(5, argv2, klass, 1);
2759 date_s_valid_weeknum_p(
int argc,
VALUE *argv,
VALUE klass)
2761 VALUE vy, vw, vd, vf, vsg;
2764 rb_scan_args(argc, argv,
"41", &vy, &vw, &vd, &vf, &vsg);
2775 if (
NIL_P(valid_weeknum_sub(5, argv2, klass, 0)))
2781 valid_nth_kday_sub(
int argc,
VALUE *argv,
VALUE klass,
int need_jd)
2784 int m,
n, k, ry, rm, rn, rk;
2797 if (!valid_nth_kday_p(y, m, n, k, sg,
2799 &rm, &rn, &rk, &rjd,
2810 date_s__valid_nth_kday_p(
int argc,
VALUE *argv,
VALUE klass)
2812 VALUE vy, vm, vn, vk, vsg;
2815 rb_scan_args(argc, argv,
"41", &vy, &vm, &vn, &vk, &vsg);
2826 return valid_nth_kday_sub(5, argv2, klass, 1);
2830 date_s_valid_nth_kday_p(
int argc,
VALUE *argv,
VALUE klass)
2832 VALUE vy, vm, vn, vk, vsg;
2835 rb_scan_args(argc, argv,
"41", &vy, &vm, &vn, &vk, &vsg);
2846 if (
NIL_P(valid_nth_kday_sub(5, argv2, klass, 0)))
2915 int y,
int m,
int d,
2935 int y,
int m,
int d,
2936 int h,
int min,
int s,
2984 int *rof,
double *rsg)
3022 date_s_new_bang(
int argc,
VALUE *argv,
VALUE klass)
3040 &nth, &jd, &df, &sf, &rof, &rsg);
3107 #define jd_trunc d_trunc
3108 #define k_trunc d_trunc
3161 #define num2num_with_frac(s,n) \
3163 s = s##_trunc(v##s, &fr);\
3164 if (f_nonzero_p(fr)) {\
3166 rb_raise(rb_eArgError, "invalid fraction");\
3171 #define num2int_with_frac(s,n) \
3173 s = NUM2INT(s##_trunc(v##s, &fr));\
3174 if (f_nonzero_p(fr)) {\
3176 rb_raise(rb_eArgError, "invalid fraction");\
3181 #define canon24oc() \
3185 fr2 = f_add(fr2, INT2FIX(1));\
3189 #define add_frac() \
3191 if (f_nonzero_p(fr2))\
3192 ret = d_lite_plus(ret, fr2);\
3195 #define val2sg(vsg,dsg) \
3197 dsg = NUM2DBL(vsg);\
3198 if (!c_valid_start_p(dsg)) {\
3200 rb_warning("invalid start is ignored");\
3272 VALUE vy, vd, vsg, y, fr, fr2,
ret;
3294 int ry, rd, rjd, ns;
3340 VALUE vy, vm, vd, vsg, y, fr, fr2,
ret;
3380 int ry, rm, rd, rjd, ns;
3417 VALUE vy, vw, vd, vsg, y, fr, fr2,
ret;
3442 int ry, rw, rd, rjd, ns;
3462 date_s_weeknum(
int argc,
VALUE *argv,
VALUE klass)
3464 VALUE vy, vw, vd, vf, vsg, y, fr, fr2,
ret;
3468 rb_scan_args(argc, argv,
"05", &vy, &vw, &vd, &vf, &vsg);
3492 int ry, rw, rd, rjd, ns;
3511 date_s_nth_kday(
int argc,
VALUE *argv,
VALUE klass)
3513 VALUE vy, vm, vn, vk, vsg, y, fr, fr2,
ret;
3517 rb_scan_args(argc, argv,
"05", &vy, &vm, &vn, &vk, &vsg);
3541 int ry, rm, rn, rk, rjd, ns;
3543 if (!valid_nth_kday_p(y, m, n, k, sg,
3545 &rm, &rn, &rk, &rjd,
3560 #if !defined(HAVE_GMTIME_R)
3564 auto struct tm *
tmp = gmtime(t);
3573 auto struct tm *
tmp = localtime(t);
3612 y = tm.tm_year + 1900;
3630 #define set_hash0(k,v) rb_hash_aset(hash, k, v)
3631 #define ref_hash0(k) rb_hash_aref(hash, k)
3632 #define del_hash0(k) rb_hash_delete(hash, k)
3634 #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
3635 #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
3636 #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
3644 if (!
NIL_P(seconds)) {
3670 #define sym(x) ID2SYM(rb_intern(x))
3777 int i, eno = 0,
idx = 0;
3810 if (k ==
sym(
"ordinal")) {
3819 else if (k ==
sym(
"civil")) {
3836 else if (k ==
sym(
"commercial")) {
3853 else if (k ==
sym(
"wday")) {
3860 else if (k ==
sym(
"wnum0")) {
3877 else if (k ==
sym(
"wnum1")) {
3896 if (g && k ==
sym(
"time")) {
3927 int ry, rd, rjd, ns;
3942 int ry, rm, rd, rjd, ns;
3957 int ry, rw, rd, rjd, ns;
3972 int ry, rw, rd, rjd, ns;
4008 VALUE year, mon, mday;
4020 VALUE year, week, wday;
4040 VALUE year, week, wday;
4060 VALUE year, week, wday;
4127 const char *default_fmt)
4138 "string should have ASCII compatible encoding");
4143 flen =
strlen(default_fmt);
4149 "format should have ASCII compatible encoding");
4250 "string should have ASCII compatible encoding");
4495 str =
rb_str_new2(
"Mon, 1 Jan -4712 00:00:00 +0000");
4537 str =
rb_str_new2(
"Mon, 01 Jan -4712 00:00:00 GMT");
4636 #define val2off(vof,iof) \
4638 if (!offset_to_sec(vof, &iof)) {\
4640 rb_warning("invalid offset is ignored");\
4646 d_lite_initialize(
int argc,
VALUE *argv,
VALUE self)
4648 VALUE jd, vjd, vdf, sf, vsf, vof, vsg;
4655 rb_scan_args(argc, argv,
"05", &vjd, &vdf, &vsf, &vof, &vsg);
4694 "cannot load complex into simple");
4722 "cannot load complex into simple");
4733 d_lite_fill(
VALUE self)
4963 d_lite_wnum0(
VALUE self)
4970 d_lite_wnum1(
VALUE self)
5240 int rjd, ns, ry, rm, rd;
5461 switch (
TYPE(other)) {
5500 dat->c.df, dat->c.sf,
5501 dat->c.of, dat->c.sg,
5539 jd =
m_jd(dat) + jd;
5565 dat->c.df, dat->c.sf,
5566 dat->c.of, dat->c.sg,
5639 df =
m_df(dat) + df;
5653 jd =
m_jd(dat) + jd;
5693 #ifdef CANONICALIZATION_FOR_MATHN
5749 df =
m_df(dat) + df;
5763 jd =
m_jd(dat) + jd;
5884 switch (
TYPE(other)) {
5986 &rm, &rd, &rjd, &ns))
6096 VALUE limit, step, date;
6201 a_nth =
m_nth(adat);
6202 b_nth =
m_nth(bdat);
6215 else if (
f_lt_p(a_sf, b_sf)) {
6222 else if (a_df < b_df) {
6229 else if (a_jd < b_jd) {
6236 else if (
f_lt_p(a_nth, b_nth)) {
6272 return cmp_dd(
self, other);
6279 a_nth =
m_nth(adat);
6280 b_nth =
m_nth(bdat);
6287 else if (a_jd < b_jd) {
6294 else if (a_nth < b_nth) {
6313 a_nth =
m_nth(adat);
6314 b_nth =
m_nth(bdat);
6318 if (a_year == b_year) {
6320 a_mon =
m_mon(adat);
6321 b_mon =
m_mon(bdat);
6322 if (a_mon == b_mon) {
6325 if (a_mday == b_mday) {
6328 else if (a_mday < b_mday) {
6335 else if (a_mon < b_mon) {
6347 else if (a_pd < b_pd) {
6355 else if (a_year < b_year) {
6362 else if (
f_lt_p(a_nth, b_nth)) {
6418 a_nth =
m_nth(adat);
6419 b_nth =
m_nth(bdat);
6439 a_nth =
m_nth(adat);
6440 b_nth =
m_nth(bdat);
6444 if (a_year == b_year) {
6446 a_mon =
m_mon(adat);
6447 b_mon =
m_mon(bdat);
6448 if (a_mon == b_mon) {
6451 if (a_mday == b_mday)
6515 mk_inspect_flags(
union DateData *x)
6527 mk_inspect_raw(
union DateData *x,
const char *klass)
6537 "(%sth,%dj),+0s,%.0fj; "
6539 klass ? klass :
"?",
6542 x->
s.
year, x->
s.mon, x->
s.mday,
6558 "(%sth,%dj,%ds,%sn),%+ds,%.0fj; "
6559 "%dy%dm%dd %dh%dm%ds; %s>",
6560 klass ? klass :
"?",
6565 x->
c.
year, x->
c.mon, x->
c.mday,
6566 x->
c.hour, x->
c.min, x->
c.sec,
6578 d_lite_inspect_raw(
VALUE self)
6594 "#<%s: %s ((%sj,%ds,%sn),%+ds,%.0fj)>",
6595 klass ? klass :
"?",
6627 size_t date_strftime(
char *s,
size_t maxsize,
const char *format,
6630 #define SMALLBUF 100
6644 if (len != 0 || (**buf ==
'\0' &&
errno != ERANGE))
return len;
6645 for (size=1024; ; size*=2) {
6658 if (size >= 1024 * flen) {
6682 #define MILLISECOND_IN_NANOSECONDS 1000000
6735 tmx->
dat = (
void *)dat;
6741 const char *default_fmt,
6759 "format should have ASCII compatible encoding");
6764 (*func)(
self, &tmx);
6765 if (memchr(fmt,
'\0', len)) {
6767 const char *
p =
fmt, *pe = fmt +
len;
6774 if (buf != buffer) {
6778 for (fmt = p; p < pe && !*
p; ++
p);
6789 if (buf != buffer)
xfree(buf);
6987 (*func)(
self, &tmx);
6990 if (buf != buffer)
xfree(buf);
7109 d_lite_marshal_dump_old(
VALUE self)
7169 VALUE ajd, of, sg, nth, sf;
7188 &nth, &jd, &df, &sf, &rof, &rsg);
7195 "cannot load complex into simple");
7220 "cannot load complex into simple");
7269 VALUE vjd, vh, vmin, vs, vof, vsg, jd, fr, fr2,
ret;
7273 rb_scan_args(argc, argv,
"06", &vjd, &vh, &vmin, &vs, &vof, &vsg);
7299 int rh, rmin, rs, rjd, rjd2;
7337 VALUE vy, vd, vh, vmin, vs, vof, vsg, y, fr, fr2,
ret;
7338 int d, h,
min,
s, rof;
7341 rb_scan_args(argc, argv,
"07", &vy, &vd, &vh, &vmin, &vs, &vof, &vsg);
7370 int ry, rd, rh, rmin, rs, rjd, rjd2, ns;
7413 VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2,
ret;
7414 int m,
d, h,
min,
s, rof;
7417 rb_scan_args(argc, argv,
"08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
7449 int ry, rm, rd, rh, rmin, rs;
7469 int ry, rm, rd, rh, rmin, rs, rjd, rjd2, ns;
7510 VALUE vy, vw, vd, vh, vmin, vs, vof, vsg, y, fr, fr2,
ret;
7511 int w,
d, h,
min,
s, rof;
7514 rb_scan_args(argc, argv,
"08", &vy, &vw, &vd, &vh, &vmin, &vs, &vof, &vsg);
7546 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7575 datetime_s_weeknum(
int argc,
VALUE *argv,
VALUE klass)
7577 VALUE vy, vw, vd, vf, vh, vmin, vs, vof, vsg, y, fr, fr2,
ret;
7578 int w,
d,
f, h,
min,
s, rof;
7582 &vh, &vmin, &vs, &vof, &vsg);
7617 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7644 datetime_s_nth_kday(
int argc,
VALUE *argv,
VALUE klass)
7646 VALUE vy, vm, vn, vk, vh, vmin, vs, vof, vsg, y, fr, fr2,
ret;
7647 int m,
n, k, h,
min,
s, rof;
7651 &vh, &vmin, &vs, &vof, &vsg);
7686 int ry, rm, rn, rk, rh, rmin, rs, rjd, rjd2, ns;
7688 if (!valid_nth_kday_p(y, m, n, k, sg,
7690 &rm, &rn, &rk, &rjd,
7726 #ifdef HAVE_CLOCK_GETTIME
7734 int y, ry,
m,
d, h,
min,
s;
7743 #ifdef HAVE_CLOCK_GETTIME
7744 if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
7756 y = tm.tm_year + 1900;
7764 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
7766 #elif defined(HAVE_VAR_TIMEZONE)
7767 #ifdef HAVE_VAR_ALTZONE
7768 of = (long)-((tm.tm_isdst > 0) ? altzone :
timezone);
7776 of += (long)difftime(sec2, sec);
7779 #elif defined(HAVE_TIMEGM)
7784 of = (long)difftime(sec2, sec);
7793 tm2.tm_isdst = tm.tm_isdst;
7794 sec2 = mktime(&tm2);
7795 of = (long)difftime(sec, sec2);
7798 #ifdef HAVE_CLOCK_GETTIME
8138 str =
rb_str_new2(
"Mon, 1 Jan -4712 00:00:00 +0000");
8168 str =
rb_str_new2(
"Mon, 01 Jan -4712 00:00:00 GMT");
8406 "%Y-%m-%dT%H:%M:%S%:z",
set_tmx);
8504 #define f_getlocal(x) rb_funcall(x, rb_intern("getlocal"), 0)
8505 #define f_subsec(x) rb_funcall(x, rb_intern("subsec"), 0)
8506 #define f_utc_offset(x) rb_funcall(x, rb_intern("utc_offset"), 0)
8507 #define f_local3(x,y,m,d) rb_funcall(x, rb_intern("local"), 3, y, m, d)
8508 #define f_utc6(x,y,m,d,h,min,s) rb_funcall(x, rb_intern("utc"), 6,\
8563 int ry,
m,
d, h,
min,
s, of;
8737 #define MIN_YEAR -4713
8738 #define MAX_YEAR 1000000
8740 #define MAX_JD 366963925
8743 test_civil(
int from,
int to,
double sg)
8747 fprintf(stderr,
"test_civil: %d...%d (%d) - %.0f\n",
8748 from, to, to - from, sg);
8749 for (j = from; j <= to; j++) {
8750 int y,
m,
d, rj, ns;
8755 fprintf(stderr,
"%d != %d\n", j, rj);
8763 date_s_test_civil(
VALUE klass)
8765 if (!test_civil(MIN_JD, MIN_JD + 366,
GREGORIAN))
8767 if (!test_civil(2305814, 2598007,
GREGORIAN))
8769 if (!test_civil(MAX_JD - 366, MAX_JD,
GREGORIAN))
8772 if (!test_civil(MIN_JD, MIN_JD + 366,
ITALY))
8774 if (!test_civil(2305814, 2598007,
ITALY))
8776 if (!test_civil(MAX_JD - 366, MAX_JD,
ITALY))
8783 test_ordinal(
int from,
int to,
double sg)
8787 fprintf(stderr,
"test_ordinal: %d...%d (%d) - %.0f\n",
8788 from, to, to - from, sg);
8789 for (j = from; j <= to; j++) {
8795 fprintf(stderr,
"%d != %d\n", j, rj);
8803 date_s_test_ordinal(
VALUE klass)
8805 if (!test_ordinal(MIN_JD, MIN_JD + 366,
GREGORIAN))
8807 if (!test_ordinal(2305814, 2598007,
GREGORIAN))
8809 if (!test_ordinal(MAX_JD - 366, MAX_JD,
GREGORIAN))
8812 if (!test_ordinal(MIN_JD, MIN_JD + 366,
ITALY))
8814 if (!test_ordinal(2305814, 2598007,
ITALY))
8816 if (!test_ordinal(MAX_JD - 366, MAX_JD,
ITALY))
8823 test_commercial(
int from,
int to,
double sg)
8827 fprintf(stderr,
"test_commercial: %d...%d (%d) - %.0f\n",
8828 from, to, to - from, sg);
8829 for (j = from; j <= to; j++) {
8830 int y, w,
d, rj, ns;
8835 fprintf(stderr,
"%d != %d\n", j, rj);
8843 date_s_test_commercial(
VALUE klass)
8845 if (!test_commercial(MIN_JD, MIN_JD + 366,
GREGORIAN))
8847 if (!test_commercial(2305814, 2598007,
GREGORIAN))
8849 if (!test_commercial(MAX_JD - 366, MAX_JD,
GREGORIAN))
8852 if (!test_commercial(MIN_JD, MIN_JD + 366,
ITALY))
8854 if (!test_commercial(2305814, 2598007,
ITALY))
8856 if (!test_commercial(MAX_JD - 366, MAX_JD,
ITALY))
8863 test_weeknum(
int from,
int to,
int f,
double sg)
8867 fprintf(stderr,
"test_weeknum: %d...%d (%d) - %.0f\n",
8868 from, to, to - from, sg);
8869 for (j = from; j <= to; j++) {
8870 int y, w,
d, rj, ns;
8875 fprintf(stderr,
"%d != %d\n", j, rj);
8883 date_s_test_weeknum(
VALUE klass)
8887 for (f = 0; f <= 1; f++) {
8888 if (!test_weeknum(MIN_JD, MIN_JD + 366, f,
GREGORIAN))
8890 if (!test_weeknum(2305814, 2598007, f,
GREGORIAN))
8892 if (!test_weeknum(MAX_JD - 366, MAX_JD, f,
GREGORIAN))
8895 if (!test_weeknum(MIN_JD, MIN_JD + 366, f,
ITALY))
8897 if (!test_weeknum(2305814, 2598007, f,
ITALY))
8899 if (!test_weeknum(MAX_JD - 366, MAX_JD, f,
ITALY))
8907 test_nth_kday(
int from,
int to,
double sg)
8911 fprintf(stderr,
"test_nth_kday: %d...%d (%d) - %.0f\n",
8912 from, to, to - from, sg);
8913 for (j = from; j <= to; j++) {
8914 int y,
m,
n, k, rj, ns;
8916 c_jd_to_nth_kday(j, sg, &y, &m, &n, &k);
8917 c_nth_kday_to_jd(y, m, n, k, sg, &rj, &ns);
8919 fprintf(stderr,
"%d != %d\n", j, rj);
8927 date_s_test_nth_kday(
VALUE klass)
8929 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
GREGORIAN))
8931 if (!test_nth_kday(2305814, 2598007,
GREGORIAN))
8933 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
GREGORIAN))
8936 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
ITALY))
8938 if (!test_nth_kday(2305814, 2598007,
ITALY))
8940 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
ITALY))
8961 if (!test_unit_v2v(
INT2FIX(0), conv1, conv2))
8963 if (!test_unit_v2v(
INT2FIX(1), conv1, conv2))
8965 if (!test_unit_v2v(
INT2FIX(2), conv1, conv2))
8967 if (!test_unit_v2v(
INT2FIX(3), conv1, conv2))
8969 if (!test_unit_v2v(
INT2FIX(11), conv1, conv2))
8971 if (!test_unit_v2v(
INT2FIX(65535), conv1, conv2))
8973 if (!test_unit_v2v(
INT2FIX(1073741823), conv1, conv2))
8975 if (!test_unit_v2v(
INT2NUM(1073741824), conv1, conv2))
8992 if (!test_unit_v2v_iter2(conv1, conv2))
8994 if (!test_unit_v2v_iter2(conv2, conv1))
9000 date_s_test_unit_conv(
VALUE klass)
9004 if (!test_unit_v2v_iter(ms_to_sec,
sec_to_ms))
9006 if (!test_unit_v2v_iter(
ns_to_day, day_to_ns))
9014 date_s_test_all(
VALUE klass)
9016 if (date_s_test_civil(klass) ==
Qfalse)
9018 if (date_s_test_ordinal(klass) ==
Qfalse)
9020 if (date_s_test_commercial(klass) ==
Qfalse)
9022 if (date_s_test_weeknum(klass) ==
Qfalse)
9024 if (date_s_test_nth_kday(klass) ==
Qfalse)
9026 if (date_s_test_unit_conv(klass) ==
Qfalse)
9034 "January",
"February",
"March",
9035 "April",
"May",
"June",
9036 "July",
"August",
"September",
9037 "October",
"November",
"December"
9042 "Jan",
"Feb",
"Mar",
"Apr",
9043 "May",
"Jun",
"Jul",
"Aug",
9044 "Sep",
"Oct",
"Nov",
"Dec"
9048 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
9049 "Thursday",
"Friday",
"Saturday"
9053 "Sun",
"Mon",
"Tue",
"Wed",
9064 for (i = 0; i <
len; i++) {
9083 #define rb_intern(str) rb_intern_const(str)
9085 assert(fprintf(stderr,
"assert() is now active\n"));
9094 #if (LONG_MAX / DAY_IN_SECONDS) > SECOND_IN_NANOSECONDS
9097 #elif defined HAVE_LONG_LONG
9099 SECOND_IN_NANOSECONDS);
9102 INT2FIX(SECOND_IN_NANOSECONDS));
9359 #define de_define_private_method rb_define_private_method
9361 date_s__valid_jd_p, -1);
9362 de_define_private_method(
CLASS_OF(
cDate),
"_valid_ordinal?",
9363 date_s__valid_ordinal_p, -1);
9365 date_s__valid_civil_p, -1);
9367 date_s__valid_civil_p, -1);
9368 de_define_private_method(
CLASS_OF(
cDate),
"_valid_commercial?",
9369 date_s__valid_commercial_p, -1);
9370 de_define_private_method(
CLASS_OF(
cDate),
"_valid_weeknum?",
9371 date_s__valid_weeknum_p, -1);
9372 de_define_private_method(
CLASS_OF(
cDate),
"_valid_nth_kday?",
9373 date_s__valid_nth_kday_p, -1);
9386 date_s_valid_weeknum_p, -1);
9387 de_define_private_method(
CLASS_OF(
cDate),
"valid_nth_kday?",
9388 date_s_valid_nth_kday_p, -1);
9390 date_s_zone_to_diff, 1);
9400 #define de_define_singleton_method rb_define_singleton_method
9401 #define de_define_alias rb_define_alias
9402 de_define_singleton_method(
cDate,
"new!", date_s_new_bang, -1);
9413 de_define_singleton_method(
cDate,
"weeknum", date_s_weeknum, -1);
9414 de_define_singleton_method(
cDate,
"nth_kday", date_s_nth_kday, -1);
9438 #define de_define_method rb_define_method
9439 de_define_method(
cDate,
"initialize", d_lite_initialize, -1);
9444 de_define_method(
cDate,
"fill", d_lite_fill, 0);
9466 de_define_private_method(
cDate,
"wnum0", d_lite_wnum0, 0);
9467 de_define_private_method(
cDate,
"wnum1", d_lite_wnum1, 0);
9481 de_define_method(
cDate,
"nth_kday?", d_lite_nth_kday_p, 2);
9534 de_define_method(
cDate,
"inspect_raw", d_lite_inspect_raw, 0);
9551 de_define_method(
cDate,
"marshal_dump_old", d_lite_marshal_dump_old, 0);
9569 de_define_singleton_method(
cDateTime,
"weeknum",
9570 datetime_s_weeknum, -1);
9571 de_define_singleton_method(
cDateTime,
"nth_kday",
9572 datetime_s_nth_kday, -1);
9599 #define f_public(m,s) rb_funcall(m, rb_intern("public"), 1,\
9600 ID2SYM(rb_intern(s)))
9639 de_define_singleton_method(
cDate,
"test_civil", date_s_test_civil, 0);
9640 de_define_singleton_method(
cDate,
"test_ordinal", date_s_test_ordinal, 0);
9641 de_define_singleton_method(
cDate,
"test_commercial",
9642 date_s_test_commercial, 0);
9643 de_define_singleton_method(
cDate,
"test_weeknum", date_s_test_weeknum, 0);
9644 de_define_singleton_method(
cDate,
"test_nth_kday", date_s_test_nth_kday, 0);
9645 de_define_singleton_method(
cDate,
"test_unit_conv",
9646 date_s_test_unit_conv, 0);
9647 de_define_singleton_method(
cDate,
"test_all", date_s_test_all, 0);
static VALUE d_lite_gregorian_p(VALUE self)
#define RB_TYPE_P(obj, type)
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 *))
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)
const char * rb_obj_classname(VALUE)
static VALUE d_lite_leap_p(VALUE self)
static VALUE m_real_jd(union DateData *x)
static int max(int a, int b)
#define rb_check_trusted(obj)
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)
static VALUE datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
#define Data_Make_Struct(klass, type, mark, free, sval)
#define PACK5(m, d, h, min, s)
static VALUE to_integer(VALUE x)
static VALUE d_lite_offset(VALUE self)
SSL_METHOD *(* func)(void)
#define rb_usascii_str_new2
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)
#define rb_check_frozen(obj)
RUBY_EXTERN VALUE rb_cTime
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)
VALUE rb_obj_freeze(VALUE)
static VALUE dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
static double s_virtual_sg(union DateData *x)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
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)
static VALUE dt_lite_strftime(int argc, VALUE *argv, VALUE self)
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)
static double m_virtual_sg(union DateData *x)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
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)
VALUE rb_obj_class(VALUE)
#define RETURN_ENUMERATOR(obj, argc, argv)
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)
#define rb_rational_new1(x)
#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)
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)
RUBY_EXTERN double round(double)
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)
VALUE rb_str_append(VALUE, VALUE)
static VALUE of2str(int of)
static VALUE d_lite_rshift(VALUE self, VALUE other)
VALUE rb_f_sprintf(int, const VALUE *)
static VALUE k_datetime_p(VALUE x)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
VALUE date__jisx0301(VALUE)
#define SECOND_IN_MILLISECONDS
void rb_copy_generic_ivar(VALUE, VALUE)
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_usascii_str_new(const char *, long)
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)
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)
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)
RUBY_EXTERN VALUE rb_cRational
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)
void rb_define_const(VALUE, const char *, VALUE)
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)
#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 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 c_jd_to_weeknum(int jd, int f, double sg, int *ry, int *rw, int *rd)
VALUE date__parse(VALUE str, VALUE comp)
unsigned char buf[MIME_BUF_SIZE]
static VALUE date_strftime_internal(int argc, VALUE *argv, VALUE self, const char *default_fmt, void(*func)(VALUE, struct tmx *))
VALUE rb_num_coerce_cmp(VALUE, VALUE, ID)
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)
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
VALUE rb_marshal_load(VALUE)
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)
void rb_gc_register_mark_object(VALUE)
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[])
static int min(int a, int b)
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)
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 get_c_civil(union DateData *x)
RUBY_EXTERN int isinf(double)
static VALUE dup_obj_as_complex(VALUE self)
static VALUE datetime_s_parse(int argc, VALUE *argv, VALUE klass)
static VALUE dup_obj(VALUE self)
static VALUE time_to_datetime(VALUE self)
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)
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)
#define rb_enc_str_asciicompat_p(str)
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)
static VALUE date_s_strptime(int argc, VALUE *argv, VALUE klass)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE div_df(VALUE d, VALUE *f)
static void df_to_time(int df, int *h, int *min, int *s)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
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)
static VALUE d_lite_monday_p(VALUE self)
static VALUE date_to_time(VALUE self)
static int m_sec(union DateData *x)
st_index_t rb_memhash(const void *ptr, long len)
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)
RUBY_EXTERN VALUE rb_cObject
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)
#define RARRAY_LENINT(ary)
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)
#define SECOND_IN_NANOSECONDS
VALUE rb_ary_new2(long capa)
static VALUE date_s_jd(int argc, VALUE *argv, VALUE klass)
VALUE rb_str_new(const char *, long)
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
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)
static VALUE f_gt_p(VALUE x, VALUE y)
static double positive_inf
static VALUE date_s__xmlschema(VALUE klass, VALUE str)
static VALUE datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
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)
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)
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
static int m_cwyear(union DateData *x)
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)
RUBY_EXTERN VALUE rb_cNumeric
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)
#define rb_rational_new2(x, y)
static VALUE ns_to_sec(VALUE n)
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)
static int c_find_fdoy(int y, double sg, int *rjd, int *ns)