10 #if defined(HAVE_SYS_TIME_H)
18 #include RUBY_EXTCONF_H
23 static ID id_cmp, id_le_p, id_ge_p, id_eqeq_p;
24 static VALUE cDate, cDateTime;
25 static VALUE eDateError;
26 static VALUE half_days_in_day, day_in_nanoseconds;
27 static double positive_inf, negative_inf;
29 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
31 #define f_abs(x) rb_funcall(x, rb_intern("abs"), 0)
32 #define f_negate(x) rb_funcall(x, rb_intern("-@"), 0)
33 #define f_add(x,y) rb_funcall(x, '+', 1, y)
34 #define f_sub(x,y) rb_funcall(x, '-', 1, y)
35 #define f_mul(x,y) rb_funcall(x, '*', 1, y)
36 #define f_div(x,y) rb_funcall(x, '/', 1, y)
37 #define f_quo(x,y) rb_funcall(x, rb_intern("quo"), 1, y)
38 #define f_idiv(x,y) rb_funcall(x, rb_intern("div"), 1, y)
39 #define f_mod(x,y) rb_funcall(x, '%', 1, y)
40 #define f_remainder(x,y) rb_funcall(x, rb_intern("remainder"), 1, y)
41 #define f_expt(x,y) rb_funcall(x, rb_intern("**"), 1, y)
42 #define f_floor(x) rb_funcall(x, rb_intern("floor"), 0)
43 #define f_ceil(x) rb_funcall(x, rb_intern("ceil"), 0)
44 #define f_truncate(x) rb_funcall(x, rb_intern("truncate"), 0)
45 #define f_round(x) rb_funcall(x, rb_intern("round"), 0)
47 #define f_to_i(x) rb_funcall(x, rb_intern("to_i"), 0)
48 #define f_to_r(x) rb_funcall(x, rb_intern("to_r"), 0)
49 #define f_to_s(x) rb_funcall(x, rb_intern("to_s"), 0)
50 #define f_inspect(x) rb_funcall(x, rb_intern("inspect"), 0)
52 #define f_add3(x,y,z) f_add(f_add(x, y), z)
53 #define f_sub3(x,y,z) f_sub(f_sub(x, y), z)
58 #define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
60 check_numeric(
VALUE obj,
const char* field) {
137 #define f_nonzero_p(x) (!f_zero_p(x))
140 f_negative_p(
VALUE x)
147 #define f_positive_p(x) (!f_negative_p(x))
149 #define f_ajd(x) rb_funcall(x, rb_intern("ajd"), 0)
150 #define f_jd(x) rb_funcall(x, rb_intern("jd"), 0)
151 #define f_year(x) rb_funcall(x, rb_intern("year"), 0)
152 #define f_mon(x) rb_funcall(x, rb_intern("mon"), 0)
153 #define f_mday(x) rb_funcall(x, rb_intern("mday"), 0)
154 #define f_wday(x) rb_funcall(x, rb_intern("wday"), 0)
155 #define f_hour(x) rb_funcall(x, rb_intern("hour"), 0)
156 #define f_min(x) rb_funcall(x, rb_intern("min"), 0)
157 #define f_sec(x) rb_funcall(x, rb_intern("sec"), 0)
160 #define NDIV(x,y) (-(-((x)+1)/(y))-1)
161 #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
162 #define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d))
163 #define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d))
165 #define HAVE_JD (1 << 0)
166 #define HAVE_DF (1 << 1)
167 #define HAVE_CIVIL (1 << 2)
168 #define HAVE_TIME (1 << 3)
169 #define COMPLEX_DAT (1 << 7)
171 #define have_jd_p(x) ((x)->flags & HAVE_JD)
172 #define have_df_p(x) ((x)->flags & HAVE_DF)
173 #define have_civil_p(x) ((x)->flags & HAVE_CIVIL)
174 #define have_time_p(x) ((x)->flags & HAVE_TIME)
175 #define complex_dat_p(x) ((x)->flags & COMPLEX_DAT)
176 #define simple_dat_p(x) (!complex_dat_p(x))
178 #define ITALY 2299161
179 #define ENGLAND 2361222
180 #define JULIAN positive_inf
181 #define GREGORIAN negative_inf
182 #define DEFAULT_SG ITALY
184 #define UNIX_EPOCH_IN_CJD INT2FIX(2440588)
186 #define MINUTE_IN_SECONDS 60
187 #define HOUR_IN_SECONDS 3600
188 #define DAY_IN_SECONDS 86400
189 #define SECOND_IN_MILLISECONDS 1000
190 #define SECOND_IN_NANOSECONDS 1000000000
192 #define JC_PERIOD0 1461
193 #define GC_PERIOD0 146097
194 #define CM_PERIOD0 71149239
195 #define CM_PERIOD (0xfffffff / CM_PERIOD0 * CM_PERIOD0)
196 #define CM_PERIOD_JCY (CM_PERIOD / JC_PERIOD0 * 4)
197 #define CM_PERIOD_GCY (CM_PERIOD / GC_PERIOD0 * 400)
199 #define REFORM_BEGIN_YEAR 1582
200 #define REFORM_END_YEAR 1930
201 #define REFORM_BEGIN_JD 2298874
202 #define REFORM_END_JD 2426355
212 #define MIN_SHIFT SEC_WIDTH
213 #define HOUR_SHIFT (MIN_WIDTH + SEC_WIDTH)
214 #define MDAY_SHIFT (HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
215 #define MON_SHIFT (MDAY_WIDTH + HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
217 #define PK_MASK(x) ((1 << (x)) - 1)
219 #define EX_SEC(x) (((x) >> SEC_SHIFT) & PK_MASK(SEC_WIDTH))
220 #define EX_MIN(x) (((x) >> MIN_SHIFT) & PK_MASK(MIN_WIDTH))
221 #define EX_HOUR(x) (((x) >> HOUR_SHIFT) & PK_MASK(HOUR_WIDTH))
222 #define EX_MDAY(x) (((x) >> MDAY_SHIFT) & PK_MASK(MDAY_WIDTH))
223 #define EX_MON(x) (((x) >> MON_SHIFT) & PK_MASK(MON_WIDTH))
225 #define PACK5(m,d,h,min,s) \
226 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT) |\
227 ((h) << HOUR_SHIFT) | ((min) << MIN_SHIFT) | ((s) << SEC_SHIFT))
230 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT))
237 #if defined(FLT_RADIX) && defined(FLT_MANT_DIG) && FLT_RADIX == 2 && FLT_MANT_DIG > 22
238 #define date_sg_t float
240 #define date_sg_t double
298 union DateData *dat;\
299 TypedData_Get_Struct(x, union DateData, &d_lite_type, dat);
302 union DateData *adat;\
303 TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);
306 union DateData *bdat;\
307 TypedData_Get_Struct(x, union DateData, &d_lite_type, bdat);
310 union DateData *adat, *bdat;\
311 TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);\
312 TypedData_Get_Struct(y, union DateData, &d_lite_type, bdat);
326 #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
328 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
330 (x)->sg = (date_sg_t)(_sg);\
334 (x)->flags = (_flags) & ~COMPLEX_DAT;\
337 #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
339 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
341 (x)->sg = (date_sg_t)(_sg);\
343 (x)->pc = PACK2(_mon, _mday);\
344 (x)->flags = (_flags) & ~COMPLEX_DAT;\
349 #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
350 _year, _mon, _mday, _hour, _min, _sec, _flags) \
352 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
355 RB_OBJ_WRITE((obj), &(x)->sf, canon(_sf));\
357 (x)->sg = (date_sg_t)(_sg);\
364 (x)->flags = (_flags) | COMPLEX_DAT;\
367 #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
368 _year, _mon, _mday, _hour, _min, _sec, _flags) \
370 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
373 RB_OBJ_WRITE((obj), &(x)->sf, canon(_sf));\
375 (x)->sg = (date_sg_t)(_sg);\
377 (x)->pc = PACK5(_mon, _mday, _hour, _min, _sec);\
378 (x)->flags = (_flags) | COMPLEX_DAT;\
383 #define copy_simple_to_complex(obj, x, y) \
385 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
388 (x)->sf = INT2FIX(0);\
390 (x)->sg = (date_sg_t)((y)->sg);\
391 (x)->year = (y)->year;\
392 (x)->mon = (y)->mon;\
393 (x)->mday = (y)->mday;\
397 (x)->flags = (y)->flags;\
400 #define copy_simple_to_complex(obj, x, y) \
402 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
405 RB_OBJ_WRITE((obj), &(x)->sf, INT2FIX(0));\
407 (x)->sg = (date_sg_t)((y)->sg);\
408 (x)->year = (y)->year;\
409 (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
410 (x)->flags = (y)->flags;\
415 #define copy_complex_to_simple(obj, x, y) \
417 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
419 (x)->sg = (date_sg_t)((y)->sg);\
420 (x)->year = (y)->year;\
421 (x)->mon = (y)->mon;\
422 (x)->mday = (y)->mday;\
423 (x)->flags = (y)->flags;\
426 #define copy_complex_to_simple(obj, x, y) \
428 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
430 (x)->sg = (date_sg_t)((y)->sg);\
431 (x)->year = (y)->year;\
432 (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
433 (x)->flags = (y)->flags;\
439 static int c_valid_civil_p(
int,
int,
int,
double,
440 int *,
int *,
int *,
int *);
443 c_find_fdoy(
int y,
double sg,
int *rjd,
int *ns)
447 for (d = 1; d < 31; d++)
448 if (c_valid_civil_p(y, 1, d,
sg, &rm, &rd, rjd, ns))
454 c_find_ldoy(
int y,
double sg,
int *rjd,
int *ns)
458 for (
i = 0;
i < 30;
i++)
459 if (c_valid_civil_p(y, 12, 31 -
i,
sg, &rm, &rd, rjd, ns))
466 c_find_fdom(
int y,
int m,
double sg,
int *rjd,
int *ns)
470 for (d = 1; d < 31; d++)
471 if (c_valid_civil_p(y, m, d,
sg, &rm, &rd, rjd, ns))
478 c_find_ldom(
int y,
int m,
double sg,
int *rjd,
int *ns)
482 for (
i = 0;
i < 30;
i++)
483 if (c_valid_civil_p(y, m, 31 -
i,
sg, &rm, &rd, rjd, ns))
489 c_civil_to_jd(
int y,
int m,
int d,
double sg,
int *rjd,
int *ns)
497 a =
floor(y / 100.0);
498 b = 2 - a +
floor(a / 4.0);
499 jd =
floor(365.25 * (y + 4716)) +
500 floor(30.6001 * (m + 1)) +
513 c_jd_to_civil(
int jd,
double sg,
int *ry,
int *rm,
int *rdom)
515 double x, a, b, c, d, e, y, m, dom;
520 x =
floor((
jd - 1867216.25) / 36524.25);
521 a =
jd + 1 + x -
floor(x / 4.0);
524 c =
floor((b - 122.1) / 365.25);
525 d =
floor(365.25 * c);
526 e =
floor((b - d) / 30.6001);
527 dom = b - d -
floor(30.6001 * e);
543 c_ordinal_to_jd(
int y,
int d,
double sg,
int *rjd,
int *ns)
547 c_find_fdoy(y,
sg, rjd, &ns2);
549 *ns = (*rjd <
sg) ? 0 : 1;
553 c_jd_to_ordinal(
int jd,
double sg,
int *ry,
int *rd)
555 int rm2, rd2, rjd, ns;
557 c_jd_to_civil(
jd,
sg, ry, &rm2, &rd2);
558 c_find_fdoy(*ry,
sg, &rjd, &ns);
559 *rd = (
jd - rjd) + 1;
563 c_commercial_to_jd(
int y,
int w,
int d,
double sg,
int *rjd,
int *ns)
567 c_find_fdoy(y,
sg, &rjd2, &ns2);
570 (rjd2 -
MOD((rjd2 - 1) + 1, 7)) +
573 *ns = (*rjd <
sg) ? 0 : 1;
577 c_jd_to_commercial(
int jd,
double sg,
int *ry,
int *rw,
int *rd)
579 int ry2, rm2, rd2, a, rjd2, ns2;
581 c_jd_to_civil(
jd - 3,
sg, &ry2, &rm2, &rd2);
583 c_commercial_to_jd(a + 1, 1, 1,
sg, &rjd2, &ns2);
587 c_commercial_to_jd(a, 1, 1,
sg, &rjd2, &ns2);
590 *rw = 1 +
DIV(
jd - rjd2, 7);
591 *rd =
MOD(
jd + 1, 7);
597 c_weeknum_to_jd(
int y,
int w,
int d,
int f,
double sg,
int *rjd,
int *ns)
601 c_find_fdoy(y,
sg, &rjd2, &ns2);
603 *rjd = (rjd2 -
MOD(((rjd2 -
f) + 1), 7) - 7) + 7 * w + d;
604 *ns = (*rjd <
sg) ? 0 : 1;
608 c_jd_to_weeknum(
int jd,
int f,
double sg,
int *ry,
int *rw,
int *rd)
610 int rm, rd2, rjd, ns, j;
612 c_jd_to_civil(
jd,
sg, ry, &rm, &rd2);
613 c_find_fdoy(*ry,
sg, &rjd, &ns);
615 j =
jd - (rjd -
MOD((rjd -
f) + 1, 7)) + 7;
622 c_nth_kday_to_jd(
int y,
int m,
int n,
int k,
double sg,
int *rjd,
int *ns)
627 c_find_fdom(y, m,
sg, &rjd2, &ns2);
631 c_find_ldom(y, m,
sg, &rjd2, &ns2);
634 *rjd = (rjd2 -
MOD((rjd2 - k) + 1, 7)) + 7 *
n;
635 *ns = (*rjd <
sg) ? 0 : 1;
642 return MOD(
jd + 1, 7);
647 c_jd_to_nth_kday(
int jd,
double sg,
int *ry,
int *rm,
int *rn,
int *rk)
651 c_jd_to_civil(
jd,
sg, ry, rm, &rd);
652 c_find_fdom(*ry, *rm,
sg, &rjd, &ns2);
653 *rn =
DIV(
jd - rjd, 7) + 1;
654 *rk = c_jd_to_wday(
jd);
659 c_valid_ordinal_p(
int y,
int d,
double sg,
660 int *rd,
int *rjd,
int *ns)
667 if (!c_find_ldoy(y,
sg, &rjd2, &ns2))
669 c_jd_to_ordinal(rjd2 + d + 1,
sg, &ry2, &rd2);
674 c_ordinal_to_jd(y, d,
sg, rjd, ns);
675 c_jd_to_ordinal(*rjd,
sg, &ry2, &rd2);
676 if (ry2 != y || rd2 != d)
681 static const int monthtab[2][13] = {
682 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
683 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
687 c_julian_leap_p(
int y)
689 return MOD(y, 4) == 0;
693 c_gregorian_leap_p(
int y)
695 return (
MOD(y, 4) == 0 && y % 100 != 0) ||
MOD(y, 400) == 0;
699 c_julian_last_day_of_month(
int y,
int m)
701 assert(m >= 1 && m <= 12);
702 return monthtab[c_julian_leap_p(y) ? 1 : 0][m];
706 c_gregorian_last_day_of_month(
int y,
int m)
708 assert(m >= 1 && m <= 12);
709 return monthtab[c_gregorian_leap_p(y) ? 1 : 0][m];
713 c_valid_julian_p(
int y,
int m,
int d,
int *rm,
int *rd)
721 last = c_julian_last_day_of_month(y, m);
724 if (d < 1 || d >
last)
732 c_valid_gregorian_p(
int y,
int m,
int d,
int *rm,
int *rd)
740 last = c_gregorian_last_day_of_month(y, m);
743 if (d < 1 || d >
last)
751 c_valid_civil_p(
int y,
int m,
int d,
double sg,
752 int *rm,
int *rd,
int *rjd,
int *ns)
759 if (!c_find_ldom(y, m,
sg, rjd, ns))
761 c_jd_to_civil(*rjd + d + 1,
sg, &ry, rm, rd);
762 if (ry != y || *rm != m)
766 c_civil_to_jd(y, m, d,
sg, rjd, ns);
767 c_jd_to_civil(*rjd,
sg, &ry, rm, rd);
768 if (ry != y || *rm != m || *rd != d)
774 c_valid_commercial_p(
int y,
int w,
int d,
double sg,
775 int *rw,
int *rd,
int *rjd,
int *ns)
777 int ns2, ry2, rw2, rd2;
784 c_commercial_to_jd(y + 1, 1, 1,
sg, &rjd2, &ns2);
785 c_jd_to_commercial(rjd2 + w * 7,
sg, &ry2, &rw2, &rd2);
790 c_commercial_to_jd(y, w, d,
sg, rjd, ns);
791 c_jd_to_commercial(*rjd,
sg, &ry2, rw, rd);
792 if (y != ry2 || w != *rw || d != *rd)
798 c_valid_weeknum_p(
int y,
int w,
int d,
int f,
double sg,
799 int *rw,
int *rd,
int *rjd,
int *ns)
801 int ns2, ry2, rw2, rd2;
808 c_weeknum_to_jd(y + 1, 1,
f,
f,
sg, &rjd2, &ns2);
809 c_jd_to_weeknum(rjd2 + w * 7,
f,
sg, &ry2, &rw2, &rd2);
814 c_weeknum_to_jd(y, w, d,
f,
sg, rjd, ns);
815 c_jd_to_weeknum(*rjd,
f,
sg, &ry2, rw, rd);
816 if (y != ry2 || w != *rw || d != *rd)
823 c_valid_nth_kday_p(
int y,
int m,
int n,
int k,
double sg,
824 int *rm,
int *rn,
int *rk,
int *rjd,
int *ns)
826 int ns2, ry2, rm2, rn2, rk2;
837 c_nth_kday_to_jd(ny, nm, 1, k,
sg, &rjd2, &ns2);
838 c_jd_to_nth_kday(rjd2 +
n * 7,
sg, &ry2, &rm2, &rn2, &rk2);
839 if (ry2 != y || rm2 != m)
843 c_nth_kday_to_jd(y, m,
n, k,
sg, rjd, ns);
844 c_jd_to_nth_kday(*rjd,
sg, &ry2, rm, rn, rk);
845 if (y != ry2 || m != *rm ||
n != *rn || k != *rk)
852 c_valid_time_p(
int h,
int min,
int s,
int *rh,
int *rmin,
int *rs)
863 return !(h < 0 || h > 24 ||
864 min < 0 || min > 59 ||
866 (
h == 24 && (min > 0 || s > 0)));
870 c_valid_start_p(
double sg)
882 df_local_to_utc(
int df,
int of)
893 df_utc_to_local(
int df,
int of)
904 jd_local_to_utc(
int jd,
int df,
int of)
915 jd_utc_to_local(
int jd,
int df,
int of)
926 time_to_df(
int h,
int min,
int s)
932 df_to_time(
int df,
int *
h,
int *min,
int *s)
959 return f_quo(
n, day_in_nanoseconds);
989 safe_mul_p(
VALUE x,
long m)
1019 return f_mul(d, day_in_nanoseconds);
1058 VALUE s = day_to_sec(d);
1082 *
jd = div_day(d, &
f);
1083 *
df = div_df(
f, &
f);
1087 inline static double
1092 if (f_zero_p(x->
s.
nth))
1094 else if (f_negative_p(x->
s.
nth))
1095 return positive_inf;
1096 return negative_inf;
1099 inline static double
1104 if (f_zero_p(x->
c.
nth))
1106 else if (f_negative_p(x->
c.
nth))
1107 return positive_inf;
1108 return negative_inf;
1111 inline static double
1115 return s_virtual_sg(x);
1117 return c_virtual_sg(x);
1120 #define canonicalize_jd(_nth, _jd) \
1123 _nth = f_sub(_nth, INT2FIX(1));\
1126 if (_jd >= CM_PERIOD) {\
1127 _nth = f_add(_nth, INT2FIX(1));\
1153 c_civil_to_jd(x->
s.
year, x->
s.mon, x->
s.mday,
1154 s_virtual_sg(x), &
jd, &ns);
1157 s_virtual_sg(x), &
jd, &ns);
1172 c_jd_to_civil(x->
s.
jd, s_virtual_sg(x), &y, &m, &d);
1191 x->
c.
df = df_local_to_utc(time_to_df(x->
c.hour, x->
c.min, x->
c.sec),
1211 r = df_utc_to_local(x->
c.
df, x->
c.
of);
1212 df_to_time(r, &x->
c.hour, &x->
c.min, &x->
c.sec);
1215 int r, m, d,
h, min, s;
1220 r = df_utc_to_local(x->
c.
df, x->
c.
of);
1221 df_to_time(r, &
h, &min, &s);
1249 c_civil_to_jd(x->
c.
year, x->
c.mon, x->
c.mday,
1250 c_virtual_sg(x), &
jd, &ns);
1253 c_virtual_sg(x), &
jd, &ns);
1258 x->
c.
jd = jd_local_to_utc(
jd,
1259 time_to_df(x->
c.hour, x->
c.min, x->
c.sec),
1262 x->
c.
jd = jd_local_to_utc(
jd,
1280 int jd, y, m, d,
h, min, s;
1286 c_jd_to_civil(
jd, c_virtual_sg(x), &y, &m, &d);
1307 return jd_utc_to_local(x->
c.
jd, x->
c.
df, x->
c.
of);
1315 return df_utc_to_local(x->
c.
df, x->
c.
of);
1319 decode_year(
VALUE y,
double style,
1325 period = (style < 0) ?
1335 inth =
DIV(it, ((
long)period));
1338 it =
MOD(it, ((
long)period));
1339 *ry = (
int)it - 4712;
1351 encode_year(
VALUE nth,
int y,
double style,
1357 period = (style < 0) ?
1373 if (f_zero_p(*
nth)) {
1383 if (f_zero_p(
nth)) {
1390 inline static double
1391 guess_style(
VALUE y,
double sg)
1404 style = positive_inf;
1406 style = negative_inf;
1416 canonicalize_s_jd(
obj, x);
1420 canonicalize_c_jd(
obj, x);
1457 encode_jd(
nth,
jd, &rjd);
1484 encode_jd(
nth,
jd, &rjd);
1503 return isec_to_day(m_df(x));
1520 m_local_df_in_day(
union DateData *x)
1522 return isec_to_day(m_local_df(x));
1539 return ns_to_day(m_sf(x));
1546 return ns_to_sec(m_sf(x));
1560 fr = isec_to_day(
df);
1562 fr =
f_add(fr, ns_to_day(
sf));
1567 #define HALF_DAYS_IN_SECONDS (DAY_IN_SECONDS / 2)
1593 r =
f_add(r, isec_to_day(
df));
1622 r =
f_add(r, isec_to_day(
df));
1644 return isec_to_day(m_of(x));
1647 inline static double
1667 sg = s_virtual_sg(x);
1672 sg = c_virtual_sg(x);
1675 return sg == positive_inf;
1682 return !m_julian_p(x);
1686 m_proleptic_julian_p(
union DateData *x)
1697 m_proleptic_gregorian_p(
union DateData *x)
1733 m_gregorian_p(x) ? -1 : +1,
1780 static const int yeartab[2][13] = {
1781 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
1782 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
1786 c_julian_to_yday(
int y,
int m,
int d)
1788 assert(m >= 1 && m <= 12);
1789 return yeartab[c_julian_leap_p(y) ? 1 : 0][m] + d;
1793 c_gregorian_to_yday(
int y,
int m,
int d)
1795 assert(m >= 1 && m <= 12);
1796 return yeartab[c_gregorian_leap_p(y) ? 1 : 0][m] + d;
1806 sg = m_virtual_sg(x);
1808 if (m_proleptic_gregorian_p(x) ||
1810 return c_gregorian_to_yday(m_year(x), m_mon(x), m_mday(x));
1811 if (m_proleptic_julian_p(x))
1812 return c_julian_to_yday(m_year(x), m_mon(x), m_mday(x));
1813 c_jd_to_ordinal(
jd,
sg, &ry, &rd);
1820 return c_jd_to_wday(m_local_jd(x));
1828 c_jd_to_commercial(m_local_jd(x), m_virtual_sg(x),
1846 m_gregorian_p(x) ? -1 : +1,
1856 c_jd_to_commercial(m_local_jd(x), m_virtual_sg(x),
1877 c_jd_to_weeknum(m_local_jd(x),
f, m_virtual_sg(x),
1885 return m_wnumx(x, 0);
1891 return m_wnumx(x, 1);
1939 #define decode_offset(of,s,h,m)\
1942 s = (of < 0) ? '-' : '+';\
1943 a = (of < 0) ? -of : of;\
1944 h = a / HOUR_IN_SECONDS;\
1945 m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
1962 return of2str(m_of(x));
1974 return f_kind_of_p(x, cDate);
1978 k_numeric_p(
VALUE x)
1984 k_rational_p(
VALUE x)
1990 expect_numeric(
VALUE x)
1992 if (!k_numeric_p(x))
1998 civil_to_jd(
VALUE y,
int m,
int d,
double sg,
2003 double style = guess_style(y,
sg);
2014 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2018 decode_year(y, style,
nth, ry);
2019 c_civil_to_jd(*ry, m, d, style, rjd, ns);
2026 int *ry,
int *rm,
int *rd)
2028 decode_jd(
jd,
nth, rjd);
2029 c_jd_to_civil(*rjd,
sg, ry, rm, rd);
2033 ordinal_to_jd(
VALUE y,
int d,
double sg,
2038 double style = guess_style(y,
sg);
2049 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2053 decode_year(y, style,
nth, ry);
2054 c_ordinal_to_jd(*ry, d, style, rjd, ns);
2063 decode_jd(
jd,
nth, rjd);
2064 c_jd_to_ordinal(*rjd,
sg, ry, rd);
2068 commercial_to_jd(
VALUE y,
int w,
int d,
double sg,
2073 double style = guess_style(y,
sg);
2078 c_commercial_to_jd(
FIX2INT(y), w, d,
sg, &
jd, ns);
2084 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2088 decode_year(y, style,
nth, ry);
2089 c_commercial_to_jd(*ry, w, d, style, rjd, ns);
2096 int *ry,
int *rw,
int *rd)
2098 decode_jd(
jd,
nth, rjd);
2099 c_jd_to_commercial(*rjd,
sg, ry, rw, rd);
2103 weeknum_to_jd(
VALUE y,
int w,
int d,
int f,
double sg,
2108 double style = guess_style(y,
sg);
2119 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2123 decode_year(y, style,
nth, ry);
2124 c_weeknum_to_jd(*ry, w, d,
f, style, rjd, ns);
2131 int *ry,
int *rw,
int *rd)
2133 decode_jd(
jd,
nth, rjd);
2134 c_jd_to_weeknum(*rjd,
f,
sg, ry, rw, rd);
2138 nth_kday_to_jd(
VALUE y,
int m,
int n,
int k,
double sg,
2143 double style = guess_style(y,
sg);
2154 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2158 decode_year(y, style,
nth, ry);
2159 c_nth_kday_to_jd(*ry, m,
n, k, style, rjd, ns);
2166 int *ry,
int *rm,
int *rn,
int *rk)
2168 decode_jd(
jd,
nth, rjd);
2169 c_jd_to_nth_kday(*rjd,
sg, ry, rm, rn, rk);
2174 valid_ordinal_p(
VALUE y,
int d,
double sg,
2179 double style = guess_style(y,
sg);
2185 r = c_valid_ordinal_p(
FIX2INT(y), d,
sg, rd, &
jd, ns);
2193 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2197 decode_year(y, style,
nth, ry);
2198 r = c_valid_ordinal_p(*ry, d, style, rd, rjd, ns);
2204 valid_gregorian_p(
VALUE y,
int m,
int d,
2208 decode_year(y, -1,
nth, ry);
2209 return c_valid_gregorian_p(*ry, m, d, rm, rd);
2213 valid_civil_p(
VALUE y,
int m,
int d,
double sg,
2215 int *rm,
int *rd,
int *rjd,
2218 double style = guess_style(y,
sg);
2224 r = c_valid_civil_p(
FIX2INT(y), m, d,
sg, rm, rd, &
jd, ns);
2232 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2236 decode_year(y, style,
nth, ry);
2238 r = c_valid_gregorian_p(*ry, m, d, rm, rd);
2240 r = c_valid_julian_p(*ry, m, d, rm, rd);
2243 c_civil_to_jd(*ry, *rm, *rd, style, rjd, ns);
2249 valid_commercial_p(
VALUE y,
int w,
int d,
double sg,
2251 int *rw,
int *rd,
int *rjd,
2254 double style = guess_style(y,
sg);
2260 r = c_valid_commercial_p(
FIX2INT(y), w, d,
sg, rw, rd, &
jd, ns);
2268 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2272 decode_year(y, style,
nth, ry);
2273 r = c_valid_commercial_p(*ry, w, d, style, rw, rd, rjd, ns);
2279 valid_weeknum_p(
VALUE y,
int w,
int d,
int f,
double sg,
2281 int *rw,
int *rd,
int *rjd,
2284 double style = guess_style(y,
sg);
2290 r = c_valid_weeknum_p(
FIX2INT(y), w, d,
f,
sg, rw, rd, &
jd, ns);
2298 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2302 decode_year(y, style,
nth, ry);
2303 r = c_valid_weeknum_p(*ry, w, d,
f, style, rw, rd, rjd, ns);
2310 valid_nth_kday_p(
VALUE y,
int m,
int n,
int k,
double sg,
2312 int *rm,
int *rn,
int *rk,
int *rjd,
2315 double style = guess_style(y,
sg);
2321 r = c_valid_nth_kday_p(
FIX2INT(y), m,
n, k,
sg, rm, rn, rk, &
jd, ns);
2329 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2333 decode_year(y, style,
nth, ry);
2334 r = c_valid_nth_kday_p(*ry, m,
n, k, style, rm, rn, rk, rjd, ns);
2343 offset_to_sec(
VALUE vof,
int *rof)
2345 int try_rational = 1;
2348 switch (
TYPE(vof)) {
2354 if (
n != -1 &&
n != 0 &&
n != 1)
2372 expect_numeric(vof);
2374 if (!k_rational_p(vof)) {
2385 vs = day_to_sec(vof);
2387 if (!k_rational_p(vs)) {
2398 if (!f_eqeq_p(vn, vs))
2429 #define valid_sg(sg) \
2431 if (!c_valid_start_p(sg)) {\
2433 rb_warning("invalid start is ignored");\
2460 return valid_jd_sub(2, argv2,
klass, 1);
2498 int m, d, ry, rm, rd;
2508 if (!need_jd && (guess_style(y,
sg) < 0)) {
2509 if (!valid_gregorian_p(y, m, d,
2519 if (!valid_civil_p(y, m, d,
sg,
2526 encode_jd(
nth, rjd, &rjd2);
2535 VALUE vy, vm, vd, vsg;
2548 return valid_civil_sub(4, argv2,
klass, 1);
2570 VALUE vy, vm, vd, vsg;
2586 if (
NIL_P(valid_civil_sub(4, argv2,
klass, 0)))
2608 if (!valid_ordinal_p(y, d,
sg,
2615 encode_jd(
nth, rjd, &rjd2);
2636 return valid_ordinal_sub(3, argv2,
klass, 1);
2668 if (
NIL_P(valid_ordinal_sub(3, argv2,
klass, 0)))
2677 int w, d, ry, rw, rd;
2691 if (!valid_commercial_p(y, w, d,
sg,
2698 encode_jd(
nth, rjd, &rjd2);
2707 VALUE vy, vw, vd, vsg;
2720 return valid_commercial_sub(4, argv2,
klass, 1);
2738 VALUE vy, vw, vd, vsg;
2754 if (
NIL_P(valid_commercial_sub(4, argv2,
klass, 0)))
2764 int w, d,
f, ry, rw, rd;
2779 if (!valid_weeknum_p(y, w, d,
f,
sg,
2786 encode_jd(
nth, rjd, &rjd2);
2794 VALUE vy, vw, vd, vf, vsg;
2808 return valid_weeknum_sub(5, argv2,
klass, 1);
2814 VALUE vy, vw, vd, vf, vsg;
2828 if (
NIL_P(valid_weeknum_sub(5, argv2,
klass, 0)))
2837 int m,
n, k, ry, rm, rn, rk;
2850 if (!valid_nth_kday_p(y, m,
n, k,
sg,
2852 &rm, &rn, &rk, &rjd,
2857 encode_jd(
nth, rjd, &rjd2);
2865 VALUE vy, vm, vn, vk, vsg;
2879 return valid_nth_kday_sub(5, argv2,
klass, 1);
2885 VALUE vy, vm, vn, vk, vsg;
2899 if (
NIL_P(valid_nth_kday_sub(5, argv2,
klass, 0)))
2927 check_numeric(y,
"year");
2928 decode_year(y, +1, &
nth, &ry);
2949 check_numeric(y,
"year");
2950 decode_year(y, -1, &
nth, &ry);
2955 d_lite_gc_mark(
void *
ptr)
2967 d_lite_memsize(
const void *
ptr)
2984 int y,
int m,
int d,
3004 int y,
int m,
int d,
3005 int h,
int min,
int s,
3014 y, m, d,
h, min, s,
flags);
3025 return d_simple_new_internal(
klass,
3035 return d_complex_new_internal(
klass,
3047 return d_lite_s_alloc_complex(
klass);
3053 int *rof,
double *rsg)
3057 decode_day(
f_add(ajd, half_days_in_day),
3062 if (!f_eqeq_p(of2, t))
3065 decode_jd(
jd, rnth, rjd);
3073 rb_raise(eDateError,
"invalid day fraction");
3083 if (!c_valid_start_p(*rsg)) {
3108 old_to_new(ajd,
of,
sg,
3111 if (!
df && f_zero_p(
sf) && !rof)
3112 return d_simple_new_internal(
klass,
3118 return d_complex_new_internal(
klass,
3139 return round(d) == d;
3165 if (wholenum_p(d)) {
3176 #define jd_trunc d_trunc
3177 #define k_trunc d_trunc
3184 if (wholenum_p(
h)) {
3201 if (wholenum_p(min)) {
3202 rmin = to_integer(min);
3218 if (wholenum_p(s)) {
3230 #define num2num_with_frac(s,n) \
3232 s = s##_trunc(v##s, &fr);\
3233 if (f_nonzero_p(fr)) {\
3235 rb_raise(eDateError, "invalid fraction");\
3240 #define num2int_with_frac(s,n) \
3242 s = NUM2INT(s##_trunc(v##s, &fr));\
3243 if (f_nonzero_p(fr)) {\
3245 rb_raise(eDateError, "invalid fraction");\
3250 #define canon24oc() \
3254 fr2 = f_add(fr2, INT2FIX(1));\
3258 #define add_frac() \
3260 if (f_nonzero_p(fr2))\
3261 ret = d_lite_plus(ret, fr2);\
3264 #define val2sg(vsg,dsg) \
3266 dsg = NUM2DBL(vsg);\
3267 if (!c_valid_start_p(dsg)) {\
3269 rb_warning("invalid start is ignored");\
3291 VALUE vjd, vsg,
jd, fr, fr2, ret;
3304 check_numeric(vjd,
"jd");
3312 decode_jd(
jd, &
nth, &rjd);
3313 ret = d_simple_new_internal(
klass,
3342 VALUE vy, vd, vsg, y, fr, fr2, ret;
3357 check_numeric(vd,
"yday");
3360 check_numeric(vy,
"year");
3366 int ry, rd, rjd, ns;
3368 if (!valid_ordinal_p(y, d,
sg,
3372 rb_raise(eDateError,
"invalid date");
3374 ret = d_simple_new_internal(
klass,
3412 return date_initialize(
argc,
argv, d_lite_s_alloc_simple(
klass));
3418 VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
3439 check_numeric(vd,
"day");
3442 check_numeric(vm,
"month");
3445 check_numeric(vy,
"year");
3449 if (guess_style(y,
sg) < 0) {
3453 if (!valid_gregorian_p(y, m, d,
3456 rb_raise(eDateError,
"invalid date");
3462 int ry, rm, rd, rjd, ns;
3464 if (!valid_civil_p(y, m, d,
sg,
3468 rb_raise(eDateError,
"invalid date");
3496 VALUE vy, vw, vd, vsg, y, fr, fr2, ret;
3512 check_numeric(vd,
"cwday");
3515 check_numeric(vw,
"cweek");
3518 check_numeric(vy,
"year");
3524 int ry, rw, rd, rjd, ns;
3526 if (!valid_commercial_p(y, w, d,
sg,
3530 rb_raise(eDateError,
"invalid date");
3532 ret = d_simple_new_internal(
klass,
3546 VALUE vy, vw, vd, vf, vsg, y, fr, fr2, ret;
3574 int ry, rw, rd, rjd, ns;
3576 if (!valid_weeknum_p(y, w, d,
f,
sg,
3580 rb_raise(eDateError,
"invalid date");
3582 ret = d_simple_new_internal(
klass,
3595 VALUE vy, vm, vn, vk, vsg, y, fr, fr2, ret;
3623 int ry, rm, rn, rk, rjd, ns;
3625 if (!valid_nth_kday_p(y, m,
n, k,
sg,
3627 &rm, &rn, &rk, &rjd,
3629 rb_raise(eDateError,
"invalid date");
3631 ret = d_simple_new_internal(
klass,
3642 #if !defined(HAVE_GMTIME_R)
3662 static void set_sg(
union DateData *,
double);
3675 VALUE vsg, nth, ret;
3691 if (!localtime_r(&t, &
tm))
3698 decode_year(
INT2FIX(y), -1, &nth, &ry);
3700 ret = d_simple_new_internal(
klass,
3712 #define set_hash0(k,v) rb_hash_aset(hash, k, v)
3713 #define ref_hash0(k) rb_hash_aref(hash, k)
3714 #define del_hash0(k) rb_hash_delete(hash, k)
3716 #define sym(x) ID2SYM(rb_intern(x""))
3718 #define set_hash(k,v) set_hash0(sym(k), v)
3719 #define ref_hash(k) ref_hash0(sym(k))
3720 #define del_hash(k) del_hash0(sym(k))
3723 rt_rewrite_frags(
VALUE hash)
3728 if (!
NIL_P(seconds)) {
3729 VALUE offset, d,
h, min, s, fr;
3733 seconds =
f_add(seconds, offset);
3862 long i, eno = 0, idx = 0;
3895 if (k ==
sym(
"ordinal")) {
3898 d = date_s_today(0, (
VALUE *)0, cDate);
3904 else if (k ==
sym(
"civil")) {
3913 d = date_s_today(0, (
VALUE *)0, cDate);
3921 else if (k ==
sym(
"commercial")) {
3930 d = date_s_today(0, (
VALUE *)0, cDate);
3938 else if (k ==
sym(
"wday")) {
3940 d = date_s_today(0, (
VALUE *)0, cDate);
3945 else if (k ==
sym(
"wnum0")) {
3954 d = date_s_today(0, (
VALUE *)0, cDate);
3962 else if (k ==
sym(
"wnum1")) {
3971 d = date_s_today(0, (
VALUE *)0, cDate);
3981 if (g && k ==
sym(
"time")) {
3984 d = date_s_today(0, (
VALUE *)0, cDate);
4012 int ry, rd, rjd, ns;
4019 encode_jd(nth, rjd, &rjd2);
4027 int ry, rm, rd, rjd, ns;
4034 encode_jd(nth, rjd, &rjd2);
4042 int ry, rw, rd, rjd, ns;
4049 encode_jd(nth, rjd, &rjd2);
4057 int ry, rw, rd, rjd, ns;
4064 encode_jd(nth, rjd, &rjd2);
4075 VALUE jd = rt__valid_jd_p(vjd, sg);
4086 VALUE jd = rt__valid_ordinal_p(year, yday, sg);
4093 VALUE year, mon, mday;
4098 VALUE jd = rt__valid_civil_p(year, mon, mday, sg);
4105 VALUE year, week, wday;
4118 VALUE jd = rt__valid_commercial_p(year, week, wday, sg);
4125 VALUE year, week, wday;
4131 if (f_eqeq_p(wday,
INT2FIX(7)))
4138 VALUE jd = rt__valid_weeknum_p(year, week, wday,
INT2FIX(0), sg);
4145 VALUE year, week, wday;
4157 VALUE jd = rt__valid_weeknum_p(year, week, wday,
INT2FIX(1), sg);
4170 if (!c_valid_start_p(
NUM2DBL(sg))) {
4176 rb_raise(eDateError,
"invalid date");
4183 jd = rt__valid_civil_p(
ref_hash(
"year"),
4187 hash = rt_rewrite_frags(hash);
4188 hash = rt_complete_frags(
klass, hash);
4189 jd = rt__valid_date_frags_p(hash, sg);
4193 rb_raise(eDateError,
"invalid date");
4198 decode_jd(jd, &nth, &rjd);
4199 return d_simple_new_internal(
klass,
4208 const char *
fmt,
size_t flen,
VALUE hash);
4212 const char *default_fmt)
4214 VALUE vstr, vfmt, hash;
4223 "string should have ASCII compatible encoding");
4228 flen =
strlen(default_fmt);
4234 "format should have ASCII compatible encoding");
4313 VALUE argv2[2], hash;
4317 hash = date_s__strptime(2, argv2,
klass);
4318 return d_new_by_frags(
klass, hash, sg);
4327 VALUE vstr, vcomp, hash;
4333 "string should have ASCII compatible encoding");
4394 VALUE argv2[2], hash;
4398 hash = date_s__parse(2, argv2,
klass);
4399 return d_new_by_frags(
klass, hash, sg);
4449 return d_new_by_frags(
klass, hash, sg);
4490 return d_new_by_frags(
klass, hash, sg);
4531 return d_new_by_frags(
klass, hash, sg);
4575 return d_new_by_frags(
klass, hash, sg);
4617 return d_new_by_frags(
klass, hash, sg);
4662 return d_new_by_frags(
klass, hash, sg);
4693 dup_obj_as_complex(
VALUE self)
4718 #define val2off(vof,iof) \
4720 if (!offset_to_sec(vof, &iof)) {\
4722 rb_warning("invalid offset is ignored");\
4730 VALUE jd, vjd, vdf, sf, vsf, vof, vsg;
4753 rb_raise(eDateError,
"invalid second fraction");
4757 rb_raise(eDateError,
"invalid day fraction");
4768 decode_jd(jd, &nth, &rjd);
4769 if (!df && f_zero_p(sf) && !of) {
4775 "cannot load complex into simple");
4787 d_lite_initialize_copy(
VALUE copy,
VALUE date)
4801 adat->c.nth = bdat->s.nth;
4802 adat->c.jd = bdat->s.jd;
4806 adat->c.sg = bdat->s.sg;
4807 adat->c.year = bdat->s.year;
4809 adat->c.mon = bdat->s.mon;
4810 adat->c.mday = bdat->s.mday;
4811 adat->c.hour = bdat->s.hour;
4812 adat->c.min = bdat->s.min;
4813 adat->c.sec = bdat->s.sec;
4815 adat->c.pc = bdat->s.pc;
4822 "cannot load complex into simple");
4832 d_lite_fill(
VALUE self)
4861 d_lite_ajd(
VALUE self)
4878 d_lite_amjd(
VALUE self)
4895 d_lite_jd(
VALUE self)
4898 return m_real_local_jd(dat);
4912 d_lite_mjd(
VALUE self)
4928 d_lite_ld(
VALUE self)
4944 d_lite_year(
VALUE self)
4947 return m_real_year(dat);
4959 d_lite_yday(
VALUE self)
4975 d_lite_mon(
VALUE self)
4991 d_lite_mday(
VALUE self)
5006 d_lite_day_fraction(
VALUE self)
5024 d_lite_cwyear(
VALUE self)
5027 return m_real_cwyear(dat);
5039 d_lite_cweek(
VALUE self)
5054 d_lite_cwday(
VALUE self)
5062 d_lite_wnum0(
VALUE self)
5069 d_lite_wnum1(
VALUE self)
5085 d_lite_wday(
VALUE self)
5098 d_lite_sunday_p(
VALUE self)
5111 d_lite_monday_p(
VALUE self)
5124 d_lite_tuesday_p(
VALUE self)
5137 d_lite_wednesday_p(
VALUE self)
5150 d_lite_thursday_p(
VALUE self)
5163 d_lite_friday_p(
VALUE self)
5176 d_lite_saturday_p(
VALUE self)
5190 if (
NUM2INT(k) != m_wday(dat))
5193 c_nth_kday_to_jd(m_year(dat), m_mon(dat),
5196 if (m_local_jd(dat) != rjd)
5211 d_lite_hour(
VALUE self)
5227 d_lite_min(
VALUE self)
5243 d_lite_sec(
VALUE self)
5259 d_lite_sec_fraction(
VALUE self)
5262 return m_sf_in_sec(dat);
5274 d_lite_offset(
VALUE self)
5277 return m_of_in_day(dat);
5289 d_lite_zone(
VALUE self)
5305 d_lite_julian_p(
VALUE self)
5321 d_lite_gregorian_p(
VALUE self)
5337 d_lite_leap_p(
VALUE self)
5339 int rjd, ns, ry, rm, rd;
5342 if (m_gregorian_p(dat))
5343 return f_boolcast(c_gregorian_leap_p(m_year(dat)));
5345 c_civil_to_jd(m_year(dat), 3, 1, m_virtual_sg(dat),
5347 c_jd_to_civil(rjd - 1, m_virtual_sg(dat), &ry, &rm, &rd);
5361 d_lite_start(
VALUE self)
5396 set_sg(
union DateData *x,
double sg)
5411 dup_obj_with_new_start(
VALUE obj,
double sg)
5442 return dup_obj_with_new_start(
self, sg);
5452 d_lite_italy(
VALUE self)
5454 return dup_obj_with_new_start(
self,
ITALY);
5464 d_lite_england(
VALUE self)
5466 return dup_obj_with_new_start(
self,
ENGLAND);
5476 d_lite_julian(
VALUE self)
5478 return dup_obj_with_new_start(
self,
JULIAN);
5488 d_lite_gregorian(
VALUE self)
5490 return dup_obj_with_new_start(
self,
GREGORIAN);
5504 dup_obj_with_new_offset(
VALUE obj,
int of)
5536 return dup_obj_with_new_offset(
self, rof);
5558 int try_rational = 1;
5562 switch (
TYPE(other)) {
5579 jd = m_jd(dat) + (
int)t;
5593 dat->c.df, dat->c.sf,
5594 dat->c.of, dat->c.
sg,
5632 jd = m_jd(dat) + jd;
5639 nth =
f_add(m_nth(dat), nth);
5651 dat->c.df, dat->c.sf,
5652 dat->c.of, dat->c.
sg,
5711 sf =
f_add(m_sf(dat), sf);
5725 df = m_df(dat) + df;
5739 jd = m_jd(dat) + jd;
5746 nth =
f_add(m_nth(dat), nth);
5748 if (!df && f_zero_p(sf) && !m_of(dat))
5760 m_of(dat), m_sg(dat),
5769 expect_numeric(other);
5771 if (!k_rational_p(other)) {
5782 if (wholenum_p(other)) {
5816 sf =
f_add(m_sf(dat), sf);
5830 df = m_df(dat) + df;
5844 jd = m_jd(dat) + jd;
5851 nth =
f_add(m_nth(dat), nth);
5853 if (!df && f_zero_p(sf) && !m_of(dat))
5865 m_of(dat), m_sg(dat),
5885 n =
f_sub(m_nth(adat), m_nth(bdat));
5886 d = m_jd(adat) - m_jd(bdat);
5887 df = m_df(adat) - m_df(bdat);
5888 sf =
f_sub(m_sf(adat), m_sf(bdat));
5917 r =
f_add(r, isec_to_day(df));
5919 r =
f_add(r, ns_to_day(sf));
5947 if (k_date_p(other))
5948 return minus_dd(
self, other);
5950 switch (
TYPE(other)) {
5956 expect_numeric(other);
5960 return d_lite_plus(
self,
f_negate(other));
5978 return d_lite_plus(
self,
n);
5995 return d_lite_minus(
self,
n);
6006 d_lite_next(
VALUE self)
6008 return d_lite_next_day(0, (
VALUE *)
NULL,
self);
6037 VALUE t, y, nth, rjd2;
6062 if (valid_civil_p(y, m, d, sg,
6064 &rm, &rd, &rjd, &ns))
6067 rb_raise(eDateError,
"invalid date");
6069 encode_jd(nth, rjd, &rjd2);
6070 return d_lite_plus(
self,
f_sub(rjd2, m_real_local_jd(dat)));
6099 expect_numeric(other);
6100 return d_lite_rshift(
self,
f_negate(other));
6119 return d_lite_rshift(
self,
n);
6138 return d_lite_lshift(
self,
n);
6203 VALUE limit, step, date;
6221 while (
FIX2INT(d_lite_cmp(date, limit)) >= 0) {
6223 date = d_lite_plus(date, step);
6231 while (
FIX2INT(d_lite_cmp(date, limit)) <= 0) {
6233 date = d_lite_plus(date, step);
6254 while (
FIX2INT(d_lite_cmp(date, max)) <= 0) {
6256 date = d_lite_plus(date,
INT2FIX(1));
6276 while (
FIX2INT(d_lite_cmp(date, min)) >= 0) {
6278 date = d_lite_plus(date,
INT2FIX(-1));
6288 if (k_numeric_p(other))
6289 return INT2FIX(f_cmp(m_ajd(dat), other));
6290 else if (k_date_p(other))
6306 m_canonicalize_jd(
self, adat);
6307 m_canonicalize_jd(other, bdat);
6308 a_nth = m_nth(adat);
6309 b_nth = m_nth(bdat);
6310 if (f_eqeq_p(a_nth, b_nth)) {
6319 if (f_eqeq_p(a_sf, b_sf)) {
6322 else if (
f_lt_p(a_sf, b_sf)) {
6329 else if (a_df < b_df) {
6336 else if (a_jd < b_jd) {
6343 else if (
f_lt_p(a_nth, b_nth)) {
6371 if (!k_date_p(other))
6372 return cmp_gen(
self, other);
6378 m_gregorian_p(adat) == m_gregorian_p(bdat)))
6379 return cmp_dd(
self, other);
6385 m_canonicalize_jd(
self, adat);
6386 m_canonicalize_jd(other, bdat);
6387 a_nth = m_nth(adat);
6388 b_nth = m_nth(bdat);
6389 if (f_eqeq_p(a_nth, b_nth)) {
6395 else if (a_jd < b_jd) {
6402 else if (
f_lt_p(a_nth, b_nth)) {
6417 if (k_numeric_p(other))
6418 return f_eqeq_p(m_real_local_jd(dat), other);
6419 else if (k_date_p(other))
6420 return f_eqeq_p(m_real_local_jd(dat),
f_jd(other));
6444 if (!k_date_p(other))
6445 return equal_gen(
self, other);
6450 if (!(m_gregorian_p(adat) == m_gregorian_p(bdat)))
6451 return equal_gen(
self, other);
6457 m_canonicalize_jd(
self, adat);
6458 m_canonicalize_jd(other, bdat);
6459 a_nth = m_nth(adat);
6460 b_nth = m_nth(bdat);
6461 a_jd = m_local_jd(adat);
6462 b_jd = m_local_jd(bdat);
6463 if (f_eqeq_p(a_nth, b_nth) &&
6475 if (!k_date_p(other))
6477 return f_zero_p(d_lite_cmp(
self, other));
6482 d_lite_hash(
VALUE self)
6496 static void set_tmx(
VALUE,
struct tmx *);
6510 d_lite_to_s(
VALUE self)
6512 return strftimev(
"%Y-%m-%d",
self, set_tmx);
6536 x->
s.
year, x->
s.mon, x->
s.mday,
6548 "%dy%dm%dd %dh%dm%ds; %s>",
6553 x->
c.
year, x->
c.mon, x->
c.mday,
6554 x->
c.hour, x->
c.min, x->
c.sec,
6566 d_lite_inspect_raw(
VALUE self)
6580 m_real_jd(x), m_df(x), m_sf(x),
6596 d_lite_inspect(
VALUE self)
6605 size_t date_strftime(
char *s,
size_t maxsize,
const char *format,
6608 #define SMALLBUF 100
6610 date_strftime_alloc(
char **
buf,
const char *format,
6636 if (
size >= 1024 * flen) {
6650 s = day_to_sec(
f_sub(m_real_jd(x),
6660 #define MILLISECOND_IN_NANOSECONDS 1000000
6667 s = sec_to_ms(tmx_m_secs(x));
6691 (
VALUE (*)(
void *))m_real_year,
6692 (
int (*)(
void *))m_yday,
6693 (
int (*)(
void *))m_mon,
6694 (
int (*)(
void *))m_mday,
6695 (
VALUE (*)(
void *))m_real_cwyear,
6696 (
int (*)(
void *))m_cweek,
6697 (
int (*)(
void *))m_cwday,
6698 (
int (*)(
void *))m_wnum0,
6699 (
int (*)(
void *))m_wnum1,
6700 (
int (*)(
void *))m_wday,
6701 (
int (*)(
void *))m_hour,
6702 (
int (*)(
void *))m_min,
6703 (
int (*)(
void *))m_sec,
6704 (
VALUE (*)(
void *))m_sf_in_sec,
6705 (
VALUE (*)(
void *))tmx_m_secs,
6706 (
VALUE (*)(
void *))tmx_m_msecs,
6707 (
int (*)(
void *))tmx_m_of,
6708 (
char *(*)(
void *))tmx_m_zone
6721 const char *default_fmt,
6739 "format should have ASCII compatible encoding");
6744 (*func)(
self, &
tmx);
6751 len = date_strftime_alloc(&
buf, p, &
tmx);
6754 if (
buf != buffer) {
6758 for (
fmt = p; p < pe && !*p; ++p);
6953 return date_strftime_internal(
argc,
argv,
self,
6954 "%Y-%m-%d", set_tmx);
6966 (*func)(
self, &
tmx);
6985 d_lite_asctime(
VALUE self)
6987 return strftimev(
"%a %b %e %H:%M:%S %Y",
self, set_tmx);
6998 d_lite_iso8601(
VALUE self)
7000 return strftimev(
"%Y-%m-%d",
self, set_tmx);
7010 d_lite_rfc3339(
VALUE self)
7012 return strftimev(
"%Y-%m-%dT%H:%M:%S%:z",
self, set_tmx);
7023 d_lite_rfc2822(
VALUE self)
7025 return strftimev(
"%a, %-d %b %Y %T %z",
self, set_tmx);
7036 d_lite_httpdate(
VALUE self)
7038 volatile VALUE dup = dup_obj_with_new_offset(
self, 0);
7060 else if (d < 2424875) {
7064 else if (d < 2447535) {
7068 else if (d < 2458605) {
7091 d_lite_jisx0301(
VALUE self)
7097 fmt = jisx0301_date_format(fmtbuf,
sizeof(fmtbuf),
7098 m_real_local_jd(
dat),
7105 d_lite_marshal_dump_old(
VALUE self)
7127 d_lite_marshal_dump(
VALUE self)
7168 VALUE ajd, vof, vsg;
7174 if (!k_numeric_p(vsg))
7183 old_to_new(ajd, vof, vsg,
7184 &nth, &jd, &df, &sf, &of, &sg);
7203 if (df || !f_zero_p(sf) || of) {
7205 "cannot load complex into simple");
7230 return d_lite_marshal_load(
obj, a);
7250 VALUE vjd, vh, vmin, vs, vof, vsg, jd, fr, fr2, ret;
7269 check_numeric(vs,
"second");
7272 check_numeric(vmin,
"minute");
7275 check_numeric(vh,
"hour");
7278 check_numeric(vjd,
"jd");
7284 int rh, rmin, rs, rjd, rjd2;
7286 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7287 rb_raise(eDateError,
"invalid date");
7290 decode_jd(jd, &nth, &rjd);
7291 rjd2 = jd_local_to_utc(rjd,
7292 time_to_df(rh, rmin, rs),
7295 ret = d_complex_new_internal(
klass,
7322 VALUE vy, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7323 int d,
h, min, s, rof;
7342 check_numeric(vs,
"second");
7345 check_numeric(vmin,
"minute");
7348 check_numeric(vh,
"hour");
7351 check_numeric(vd,
"yday");
7354 check_numeric(vy,
"year");
7360 int ry, rd, rh, rmin, rs, rjd, rjd2, ns;
7362 if (!valid_ordinal_p(y, d, sg,
7366 rb_raise(eDateError,
"invalid date");
7367 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7368 rb_raise(eDateError,
"invalid date");
7371 rjd2 = jd_local_to_utc(rjd,
7372 time_to_df(rh, rmin, rs),
7375 ret = d_complex_new_internal(
klass,
7403 return datetime_initialize(
argc,
argv, d_lite_s_alloc_complex(
klass));
7409 VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7410 int m, d,
h, min, s, rof;
7418 rb_scan_args(
argc,
argv,
"08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
7435 check_numeric(vs,
"second");
7438 check_numeric(vmin,
"minute");
7441 check_numeric(vh,
"hour");
7444 check_numeric(vd,
"day");
7447 check_numeric(vm,
"month");
7450 check_numeric(vy,
"year");
7454 if (guess_style(y,
sg) < 0) {
7456 int ry, rm, rd, rh, rmin, rs;
7458 if (!valid_gregorian_p(y, m, d,
7461 rb_raise(eDateError,
"invalid date");
7462 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7463 rb_raise(eDateError,
"invalid date");
7476 int ry, rm, rd, rh, rmin, rs, rjd, rjd2, ns;
7478 if (!valid_civil_p(y, m, d,
sg,
7482 rb_raise(eDateError,
"invalid date");
7483 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7484 rb_raise(eDateError,
"invalid date");
7487 rjd2 = jd_local_to_utc(rjd,
7488 time_to_df(rh, rmin, rs),
7518 VALUE vy, vw, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7519 int w, d,
h, min, s, rof;
7522 rb_scan_args(
argc,
argv,
"08", &vy, &vw, &vd, &vh, &vmin, &vs, &vof, &vsg);
7539 check_numeric(vs,
"second");
7542 check_numeric(vmin,
"minute");
7545 check_numeric(vh,
"hour");
7548 check_numeric(vd,
"cwday");
7551 check_numeric(vw,
"cweek");
7554 check_numeric(vy,
"year");
7560 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7562 if (!valid_commercial_p(y, w, d,
sg,
7566 rb_raise(eDateError,
"invalid date");
7567 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7568 rb_raise(eDateError,
"invalid date");
7571 rjd2 = jd_local_to_utc(rjd,
7572 time_to_df(rh, rmin, rs),
7575 ret = d_complex_new_internal(
klass,
7591 VALUE vy, vw, vd, vf, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7592 int w, d,
f,
h, min, s, rof;
7596 &vh, &vmin, &vs, &vof, &vsg);
7631 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7633 if (!valid_weeknum_p(y, w, d,
f,
sg,
7637 rb_raise(eDateError,
"invalid date");
7638 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7639 rb_raise(eDateError,
"invalid date");
7642 rjd2 = jd_local_to_utc(rjd,
7643 time_to_df(rh, rmin, rs),
7645 ret = d_complex_new_internal(
klass,
7660 VALUE vy, vm, vn, vk, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7661 int m,
n, k,
h, min, s, rof;
7665 &vh, &vmin, &vs, &vof, &vsg);
7700 int ry, rm, rn, rk, rh, rmin, rs, rjd, rjd2, ns;
7702 if (!valid_nth_kday_p(y, m,
n, k,
sg,
7704 &rm, &rn, &rk, &rjd,
7706 rb_raise(eDateError,
"invalid date");
7707 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7708 rb_raise(eDateError,
"invalid date");
7711 rjd2 = jd_local_to_utc(rjd,
7712 time_to_df(rh, rmin, rs),
7714 ret = d_complex_new_internal(
klass,
7740 #ifdef HAVE_CLOCK_GETTIME
7748 int y, ry, m, d,
h, min, s;
7757 #ifdef HAVE_CLOCK_GETTIME
7767 if (!localtime_r(&sec, &
tm))
7778 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
7780 #elif defined(HAVE_TIMEZONE)
7793 #elif defined(HAVE_TIMEGM)
7805 if (!gmtime_r(&sec, &tm2))
7812 #ifdef HAVE_CLOCK_GETTIME
7815 sf = tv.tv_usec * 1000;
7823 decode_year(
INT2FIX(y), -1, &nth, &ry);
7825 ret = d_complex_new_internal(
klass,
7845 if (!c_valid_start_p(
NUM2DBL(sg))) {
7851 rb_raise(eDateError,
"invalid date");
7858 jd = rt__valid_civil_p(
ref_hash(
"year"),
7872 hash = rt_rewrite_frags(hash);
7873 hash = rt_complete_frags(
klass, hash);
7874 jd = rt__valid_date_frags_p(hash, sg);
7878 rb_raise(eDateError,
"invalid date");
7887 rb_raise(eDateError,
"invalid date");
7889 df = time_to_df(rh, rmin, rs);
7912 decode_jd(jd, &nth, &rjd);
7913 rjd2 = jd_local_to_utc(rjd, df, of);
7914 df = df_local_to_utc(df, of);
7916 return d_complex_new_internal(
klass,
7939 return date_s__strptime_internal(
argc,
argv,
klass,
"%FT%T%z");
7986 VALUE argv2[2], hash;
7990 hash = date_s__strptime(2, argv2,
klass);
7991 return dt_new_by_frags(
klass, hash, sg);
8029 VALUE argv2[2], hash;
8033 hash = date_s__parse(2, argv2,
klass);
8034 return dt_new_by_frags(
klass, hash, sg);
8068 return dt_new_by_frags(
klass, hash, sg);
8098 return dt_new_by_frags(
klass, hash, sg);
8128 return dt_new_by_frags(
klass, hash, sg);
8159 return dt_new_by_frags(
klass, hash, sg);
8189 return dt_new_by_frags(
klass, hash, sg);
8224 return dt_new_by_frags(
klass, hash, sg);
8239 dt_lite_to_s(
VALUE self)
8241 return strftimev(
"%Y-%m-%dT%H:%M:%S%:z",
self, set_tmx);
8425 return date_strftime_internal(
argc,
argv,
self,
8426 "%Y-%m-%dT%H:%M:%S%:z", set_tmx);
8430 iso8601_timediv(
VALUE self,
long n)
8432 static const char timefmt[] =
"T%H:%M:%S";
8433 static const char zone[] =
"%:z";
8438 memcpy(p, timefmt,
sizeof(timefmt)-1);
8439 p +=
sizeof(timefmt)-1;
8466 iso8601_timediv(
self,
n));
8482 return dt_lite_iso8601(
argc,
argv,
self);
8505 iso8601_timediv(
self,
n));
8510 #define f_subsec(x) rb_funcall(x, rb_intern("subsec"), 0)
8511 #define f_utc_offset(x) rb_funcall(x, rb_intern("utc_offset"), 0)
8512 #define f_local3(x,y,m,d) rb_funcall(x, rb_intern("local"), 3, y, m, d)
8521 time_to_time(
VALUE self)
8533 time_to_date(
VALUE self)
8542 decode_year(y, -1, &nth, &ry);
8544 ret = d_simple_new_internal(cDate,
8563 time_to_datetime(
VALUE self)
8565 VALUE y, sf, nth, ret;
8566 int ry, m, d,
h, min, s, of;
8581 decode_year(y, -1, &nth, &ry);
8583 ret = d_complex_new_internal(cDateTime,
8605 date_to_time(
VALUE self)
8609 if (m_julian_p(adat)) {
8610 VALUE tmp = d_lite_gregorian(
self);
8628 date_to_date(
VALUE self)
8640 date_to_datetime(
VALUE self)
8645 VALUE new = d_lite_s_alloc_simple(cDateTime);
8653 VALUE new = d_lite_s_alloc_complex(cDateTime);
8680 datetime_to_time(
VALUE self)
8682 volatile VALUE dup = dup_obj(
self);
8710 datetime_to_date(
VALUE self)
8715 VALUE new = d_lite_s_alloc_simple(cDate);
8719 bdat->s.jd = m_local_jd(adat);
8724 VALUE new = d_lite_s_alloc_simple(cDate);
8728 bdat->s.jd = m_local_jd(adat);
8742 datetime_to_datetime(
VALUE self)
8750 #define MIN_YEAR -4713
8751 #define MAX_YEAR 1000000
8753 #define MAX_JD 366963925
8756 test_civil(
int from,
int to,
double sg)
8761 from, to, to - from, sg);
8762 for (j = from; j <= to; j++) {
8763 int y, m, d, rj, ns;
8765 c_jd_to_civil(j, sg, &y, &m, &d);
8766 c_civil_to_jd(y, m, d, sg, &rj, &ns);
8778 if (!test_civil(MIN_JD, MIN_JD + 366,
GREGORIAN))
8780 if (!test_civil(2305814, 2598007,
GREGORIAN))
8782 if (!test_civil(MAX_JD - 366, MAX_JD,
GREGORIAN))
8785 if (!test_civil(MIN_JD, MIN_JD + 366,
ITALY))
8787 if (!test_civil(2305814, 2598007,
ITALY))
8789 if (!test_civil(MAX_JD - 366, MAX_JD,
ITALY))
8796 test_ordinal(
int from,
int to,
double sg)
8801 from, to, to - from, sg);
8802 for (j = from; j <= to; j++) {
8805 c_jd_to_ordinal(j, sg, &y, &d);
8806 c_ordinal_to_jd(y, d, sg, &rj, &ns);
8818 if (!test_ordinal(MIN_JD, MIN_JD + 366,
GREGORIAN))
8820 if (!test_ordinal(2305814, 2598007,
GREGORIAN))
8822 if (!test_ordinal(MAX_JD - 366, MAX_JD,
GREGORIAN))
8825 if (!test_ordinal(MIN_JD, MIN_JD + 366,
ITALY))
8827 if (!test_ordinal(2305814, 2598007,
ITALY))
8829 if (!test_ordinal(MAX_JD - 366, MAX_JD,
ITALY))
8836 test_commercial(
int from,
int to,
double sg)
8841 from, to, to - from, sg);
8842 for (j = from; j <= to; j++) {
8843 int y, w, d, rj, ns;
8845 c_jd_to_commercial(j, sg, &y, &w, &d);
8846 c_commercial_to_jd(y, w, d, sg, &rj, &ns);
8858 if (!test_commercial(MIN_JD, MIN_JD + 366,
GREGORIAN))
8860 if (!test_commercial(2305814, 2598007,
GREGORIAN))
8862 if (!test_commercial(MAX_JD - 366, MAX_JD,
GREGORIAN))
8865 if (!test_commercial(MIN_JD, MIN_JD + 366,
ITALY))
8867 if (!test_commercial(2305814, 2598007,
ITALY))
8869 if (!test_commercial(MAX_JD - 366, MAX_JD,
ITALY))
8876 test_weeknum(
int from,
int to,
int f,
double sg)
8881 from, to, to - from, sg);
8882 for (j = from; j <= to; j++) {
8883 int y, w, d, rj, ns;
8885 c_jd_to_weeknum(j,
f, sg, &y, &w, &d);
8886 c_weeknum_to_jd(y, w, d,
f, sg, &rj, &ns);
8900 for (
f = 0;
f <= 1;
f++) {
8901 if (!test_weeknum(MIN_JD, MIN_JD + 366,
f,
GREGORIAN))
8903 if (!test_weeknum(2305814, 2598007,
f,
GREGORIAN))
8905 if (!test_weeknum(MAX_JD - 366, MAX_JD,
f,
GREGORIAN))
8908 if (!test_weeknum(MIN_JD, MIN_JD + 366,
f,
ITALY))
8910 if (!test_weeknum(2305814, 2598007,
f,
ITALY))
8912 if (!test_weeknum(MAX_JD - 366, MAX_JD,
f,
ITALY))
8920 test_nth_kday(
int from,
int to,
double sg)
8925 from, to, to - from, sg);
8926 for (j = from; j <= to; j++) {
8927 int y, m,
n, k, rj, ns;
8929 c_jd_to_nth_kday(j, sg, &y, &m, &
n, &k);
8930 c_nth_kday_to_jd(y, m,
n, k, sg, &rj, &ns);
8942 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
GREGORIAN))
8944 if (!test_nth_kday(2305814, 2598007,
GREGORIAN))
8946 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
GREGORIAN))
8949 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
ITALY))
8951 if (!test_nth_kday(2305814, 2598007,
ITALY))
8953 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
ITALY))
8967 return f_eqeq_p(o,
i);
8974 if (!test_unit_v2v(
INT2FIX(0), conv1, conv2))
8976 if (!test_unit_v2v(
INT2FIX(1), conv1, conv2))
8978 if (!test_unit_v2v(
INT2FIX(2), conv1, conv2))
8980 if (!test_unit_v2v(
INT2FIX(3), conv1, conv2))
8982 if (!test_unit_v2v(
INT2FIX(11), conv1, conv2))
8984 if (!test_unit_v2v(
INT2FIX(65535), conv1, conv2))
8986 if (!test_unit_v2v(
INT2FIX(1073741823), conv1, conv2))
8988 if (!test_unit_v2v(
INT2NUM(1073741824), conv1, conv2))
9005 if (!test_unit_v2v_iter2(conv1, conv2))
9007 if (!test_unit_v2v_iter2(conv2, conv1))
9015 if (!test_unit_v2v_iter(sec_to_day, day_to_sec))
9017 if (!test_unit_v2v_iter(ms_to_sec, sec_to_ms))
9019 if (!test_unit_v2v_iter(ns_to_day, day_to_ns))
9021 if (!test_unit_v2v_iter(ns_to_sec, sec_to_ns))
9045 static const char *monthnames[] = {
9047 "January",
"February",
"March",
9048 "April",
"May",
"June",
9049 "July",
"August",
"September",
9050 "October",
"November",
"December"
9053 static const char *abbr_monthnames[] = {
9055 "Jan",
"Feb",
"Mar",
"Apr",
9056 "May",
"Jun",
"Jul",
"Aug",
9057 "Sep",
"Oct",
"Nov",
"Dec"
9060 static const char *daynames[] = {
9061 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
9062 "Thursday",
"Friday",
"Saturday"
9065 static const char *abbr_daynames[] = {
9066 "Sun",
"Mon",
"Tue",
"Wed",
9071 mk_ary_of_str(
long len,
const char *a[])
9077 for (
i = 0;
i <
len;
i++) {
9093 d_lite_zero(
VALUE x)
9102 #define rb_intern(str) rb_intern_const(str)
9111 #if (LONG_MAX / DAY_IN_SECONDS) > SECOND_IN_NANOSECONDS
9114 #elif defined HAVE_LONG_LONG
9288 mk_ary_of_str(13, abbr_monthnames));
9298 rb_define_const(cDate,
"ABBR_DAYNAMES", mk_ary_of_str(7, abbr_daynames));
9324 date_s__valid_jd_p, -1);
9326 date_s__valid_ordinal_p, -1);
9328 date_s__valid_civil_p, -1);
9330 date_s__valid_civil_p, -1);
9332 date_s__valid_commercial_p, -1);
9334 date_s__valid_weeknum_p, -1);
9336 date_s__valid_nth_kday_p, -1);
9341 date_s_valid_ordinal_p, -1);
9345 date_s_valid_commercial_p, -1);
9349 date_s_valid_weeknum_p, -1);
9351 date_s_valid_nth_kday_p, -1);
9353 date_s_zone_to_diff, 1);
9358 date_s_gregorian_leap_p, 1);
9360 date_s_gregorian_leap_p, 1);
9656 datetime_s_commercial, -1);
9660 datetime_s_weeknum, -1);
9662 datetime_s_nth_kday, -1);
9669 datetime_s__strptime, -1);
9671 datetime_s_strptime, -1);
9673 datetime_s_parse, -1);
9675 datetime_s_iso8601, -1);
9677 datetime_s_rfc3339, -1);
9679 datetime_s_xmlschema, -1);
9681 datetime_s_rfc2822, -1);
9683 datetime_s_rfc2822, -1);
9685 datetime_s_httpdate, -1);
9687 datetime_s_jisx0301, -1);
9729 date_s_test_commercial, 0);
9733 date_s_test_unit_conv, 0);