10#if defined(HAVE_SYS_TIME_H)
19#include RUBY_EXTCONF_H
24static ID id_cmp, id_le_p, id_ge_p, id_eqeq_p;
25static VALUE cDate, cDateTime;
26static VALUE eDateError;
27static VALUE half_days_in_day, day_in_nanoseconds;
28static double positive_inf, negative_inf;
30#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
32#define f_abs(x) rb_funcall(x, rb_intern("abs"), 0)
33#define f_negate(x) rb_funcall(x, rb_intern("-@"), 0)
34#define f_add(x,y) rb_funcall(x, '+', 1, y)
35#define f_sub(x,y) rb_funcall(x, '-', 1, y)
36#define f_mul(x,y) rb_funcall(x, '*', 1, y)
37#define f_div(x,y) rb_funcall(x, '/', 1, y)
38#define f_quo(x,y) rb_funcall(x, rb_intern("quo"), 1, y)
39#define f_idiv(x,y) rb_funcall(x, rb_intern("div"), 1, y)
40#define f_mod(x,y) rb_funcall(x, '%', 1, y)
41#define f_remainder(x,y) rb_funcall(x, rb_intern("remainder"), 1, y)
42#define f_expt(x,y) rb_funcall(x, rb_intern("**"), 1, y)
43#define f_floor(x) rb_funcall(x, rb_intern("floor"), 0)
44#define f_ceil(x) rb_funcall(x, rb_intern("ceil"), 0)
45#define f_truncate(x) rb_funcall(x, rb_intern("truncate"), 0)
46#define f_round(x) rb_funcall(x, rb_intern("round"), 0)
48#define f_to_i(x) rb_funcall(x, rb_intern("to_i"), 0)
49#define f_to_r(x) rb_funcall(x, rb_intern("to_r"), 0)
50#define f_to_s(x) rb_funcall(x, rb_intern("to_s"), 0)
51#define f_inspect(x) rb_funcall(x, rb_intern("inspect"), 0)
53#define f_add3(x,y,z) f_add(f_add(x, y), z)
54#define f_sub3(x,y,z) f_sub(f_sub(x, y), z)
59#define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
61check_numeric(
VALUE obj,
const char* field) {
138#define f_nonzero_p(x) (!f_zero_p(x))
148#define f_positive_p(x) (!f_negative_p(x))
150#define f_ajd(x) rb_funcall(x, rb_intern("ajd"), 0)
151#define f_jd(x) rb_funcall(x, rb_intern("jd"), 0)
152#define f_year(x) rb_funcall(x, rb_intern("year"), 0)
153#define f_mon(x) rb_funcall(x, rb_intern("mon"), 0)
154#define f_mday(x) rb_funcall(x, rb_intern("mday"), 0)
155#define f_wday(x) rb_funcall(x, rb_intern("wday"), 0)
156#define f_hour(x) rb_funcall(x, rb_intern("hour"), 0)
157#define f_min(x) rb_funcall(x, rb_intern("min"), 0)
158#define f_sec(x) rb_funcall(x, rb_intern("sec"), 0)
161#define NDIV(x,y) (-(-((x)+1)/(y))-1)
162#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
163#define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d))
164#define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d))
166#define HAVE_JD (1 << 0)
167#define HAVE_DF (1 << 1)
168#define HAVE_CIVIL (1 << 2)
169#define HAVE_TIME (1 << 3)
170#define COMPLEX_DAT (1 << 7)
172#define have_jd_p(x) ((x)->flags & HAVE_JD)
173#define have_df_p(x) ((x)->flags & HAVE_DF)
174#define have_civil_p(x) ((x)->flags & HAVE_CIVIL)
175#define have_time_p(x) ((x)->flags & HAVE_TIME)
176#define complex_dat_p(x) ((x)->flags & COMPLEX_DAT)
177#define simple_dat_p(x) (!complex_dat_p(x))
180#define ENGLAND 2361222
181#define JULIAN positive_inf
182#define GREGORIAN negative_inf
183#define DEFAULT_SG ITALY
185#define UNIX_EPOCH_IN_CJD INT2FIX(2440588)
187#define MINUTE_IN_SECONDS 60
188#define HOUR_IN_SECONDS 3600
189#define DAY_IN_SECONDS 86400
190#define SECOND_IN_MILLISECONDS 1000
191#define SECOND_IN_NANOSECONDS 1000000000
193#define JC_PERIOD0 1461
194#define GC_PERIOD0 146097
195#define CM_PERIOD0 71149239
196#define CM_PERIOD (0xfffffff / CM_PERIOD0 * CM_PERIOD0)
197#define CM_PERIOD_JCY (CM_PERIOD / JC_PERIOD0 * 4)
198#define CM_PERIOD_GCY (CM_PERIOD / GC_PERIOD0 * 400)
200#define REFORM_BEGIN_YEAR 1582
201#define REFORM_END_YEAR 1930
202#define REFORM_BEGIN_JD 2298874
203#define REFORM_END_JD 2426355
213#define MIN_SHIFT SEC_WIDTH
214#define HOUR_SHIFT (MIN_WIDTH + SEC_WIDTH)
215#define MDAY_SHIFT (HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
216#define MON_SHIFT (MDAY_WIDTH + HOUR_WIDTH + MIN_WIDTH + SEC_WIDTH)
218#define PK_MASK(x) ((1 << (x)) - 1)
220#define EX_SEC(x) (((x) >> SEC_SHIFT) & PK_MASK(SEC_WIDTH))
221#define EX_MIN(x) (((x) >> MIN_SHIFT) & PK_MASK(MIN_WIDTH))
222#define EX_HOUR(x) (((x) >> HOUR_SHIFT) & PK_MASK(HOUR_WIDTH))
223#define EX_MDAY(x) (((x) >> MDAY_SHIFT) & PK_MASK(MDAY_WIDTH))
224#define EX_MON(x) (((x) >> MON_SHIFT) & PK_MASK(MON_WIDTH))
226#define PACK5(m,d,h,min,s) \
227 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT) |\
228 ((h) << HOUR_SHIFT) | ((min) << MIN_SHIFT) | ((s) << SEC_SHIFT))
231 (((m) << MON_SHIFT) | ((d) << MDAY_SHIFT))
238#if defined(FLT_RADIX) && defined(FLT_MANT_DIG) && FLT_RADIX == 2 && FLT_MANT_DIG > 22
239#define date_sg_t float
241#define date_sg_t double
299 union DateData *dat;\
300 TypedData_Get_Struct(x, union DateData, &d_lite_type, dat);
303 union DateData *adat;\
304 TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);
307 union DateData *bdat;\
308 TypedData_Get_Struct(x, union DateData, &d_lite_type, bdat);
311 union DateData *adat, *bdat;\
312 TypedData_Get_Struct(x, union DateData, &d_lite_type, adat);\
313 TypedData_Get_Struct(y, union DateData, &d_lite_type, bdat);
327#define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
329 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
331 (x)->sg = (date_sg_t)(_sg);\
335 (x)->flags = (_flags) & ~COMPLEX_DAT;\
338#define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
340 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
342 (x)->sg = (date_sg_t)(_sg);\
344 (x)->pc = PACK2(_mon, _mday);\
345 (x)->flags = (_flags) & ~COMPLEX_DAT;\
350#define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
351_year, _mon, _mday, _hour, _min, _sec, _flags) \
353 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
356 RB_OBJ_WRITE((obj), &(x)->sf, canon(_sf));\
358 (x)->sg = (date_sg_t)(_sg);\
365 (x)->flags = (_flags) | COMPLEX_DAT;\
368#define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
369_year, _mon, _mday, _hour, _min, _sec, _flags) \
371 RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
374 RB_OBJ_WRITE((obj), &(x)->sf, canon(_sf));\
376 (x)->sg = (date_sg_t)(_sg);\
378 (x)->pc = PACK5(_mon, _mday, _hour, _min, _sec);\
379 (x)->flags = (_flags) | COMPLEX_DAT;\
384#define copy_simple_to_complex(obj, x, y) \
386 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
389 (x)->sf = INT2FIX(0);\
391 (x)->sg = (date_sg_t)((y)->sg);\
392 (x)->year = (y)->year;\
393 (x)->mon = (y)->mon;\
394 (x)->mday = (y)->mday;\
398 (x)->flags = (y)->flags;\
401#define copy_simple_to_complex(obj, x, y) \
403 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
406 RB_OBJ_WRITE((obj), &(x)->sf, INT2FIX(0));\
408 (x)->sg = (date_sg_t)((y)->sg);\
409 (x)->year = (y)->year;\
410 (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
411 (x)->flags = (y)->flags;\
416#define copy_complex_to_simple(obj, x, y) \
418 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
420 (x)->sg = (date_sg_t)((y)->sg);\
421 (x)->year = (y)->year;\
422 (x)->mon = (y)->mon;\
423 (x)->mday = (y)->mday;\
424 (x)->flags = (y)->flags;\
427#define copy_complex_to_simple(obj, x, y) \
429 RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
431 (x)->sg = (date_sg_t)((y)->sg);\
432 (x)->year = (y)->year;\
433 (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
434 (x)->flags = (y)->flags;\
440static int c_valid_civil_p(
int,
int,
int,
double,
441 int *,
int *,
int *,
int *);
444c_find_fdoy(
int y,
double sg,
int *rjd,
int *ns)
448 for (d = 1; d < 31; d++)
449 if (c_valid_civil_p(y, 1, d,
sg, &rm, &rd, rjd, ns))
455c_find_ldoy(
int y,
double sg,
int *rjd,
int *ns)
459 for (
i = 0;
i < 30;
i++)
460 if (c_valid_civil_p(y, 12, 31 -
i,
sg, &rm, &rd, rjd, ns))
467c_find_fdom(
int y,
int m,
double sg,
int *rjd,
int *ns)
471 for (d = 1; d < 31; d++)
472 if (c_valid_civil_p(y, m, d,
sg, &rm, &rd, rjd, ns))
479c_find_ldom(
int y,
int m,
double sg,
int *rjd,
int *ns)
483 for (
i = 0;
i < 30;
i++)
484 if (c_valid_civil_p(y, m, 31 -
i,
sg, &rm, &rd, rjd, ns))
490c_civil_to_jd(
int y,
int m,
int d,
double sg,
int *rjd,
int *ns)
498 a =
floor(y / 100.0);
499 b = 2 - a +
floor(a / 4.0);
500 jd =
floor(365.25 * (y + 4716)) +
501 floor(30.6001 * (m + 1)) +
514c_jd_to_civil(
int jd,
double sg,
int *ry,
int *rm,
int *rdom)
516 double x, a, b, c, d, e, y, m, dom;
521 x =
floor((
jd - 1867216.25) / 36524.25);
522 a =
jd + 1 + x -
floor(x / 4.0);
525 c =
floor((b - 122.1) / 365.25);
526 d =
floor(365.25 * c);
527 e =
floor((b - d) / 30.6001);
528 dom = b - d -
floor(30.6001 * e);
544c_ordinal_to_jd(
int y,
int d,
double sg,
int *rjd,
int *ns)
548 c_find_fdoy(y,
sg, rjd, &ns2);
550 *ns = (*rjd <
sg) ? 0 : 1;
554c_jd_to_ordinal(
int jd,
double sg,
int *ry,
int *rd)
556 int rm2, rd2, rjd, ns;
558 c_jd_to_civil(
jd,
sg, ry, &rm2, &rd2);
559 c_find_fdoy(*ry,
sg, &rjd, &ns);
560 *rd = (
jd - rjd) + 1;
564c_commercial_to_jd(
int y,
int w,
int d,
double sg,
int *rjd,
int *ns)
568 c_find_fdoy(y,
sg, &rjd2, &ns2);
571 (rjd2 -
MOD((rjd2 - 1) + 1, 7)) +
574 *ns = (*rjd <
sg) ? 0 : 1;
578c_jd_to_commercial(
int jd,
double sg,
int *ry,
int *rw,
int *rd)
580 int ry2, rm2, rd2, a, rjd2, ns2;
582 c_jd_to_civil(
jd - 3,
sg, &ry2, &rm2, &rd2);
584 c_commercial_to_jd(a + 1, 1, 1,
sg, &rjd2, &ns2);
588 c_commercial_to_jd(a, 1, 1,
sg, &rjd2, &ns2);
591 *rw = 1 +
DIV(
jd - rjd2, 7);
592 *rd =
MOD(
jd + 1, 7);
598c_weeknum_to_jd(
int y,
int w,
int d,
int f,
double sg,
int *rjd,
int *ns)
602 c_find_fdoy(y,
sg, &rjd2, &ns2);
604 *rjd = (rjd2 -
MOD(((rjd2 -
f) + 1), 7) - 7) + 7 * w + d;
605 *ns = (*rjd <
sg) ? 0 : 1;
609c_jd_to_weeknum(
int jd,
int f,
double sg,
int *ry,
int *rw,
int *rd)
611 int rm, rd2, rjd, ns, j;
613 c_jd_to_civil(
jd,
sg, ry, &rm, &rd2);
614 c_find_fdoy(*ry,
sg, &rjd, &ns);
616 j =
jd - (rjd -
MOD((rjd -
f) + 1, 7)) + 7;
623c_nth_kday_to_jd(
int y,
int m,
int n,
int k,
double sg,
int *rjd,
int *ns)
628 c_find_fdom(y, m,
sg, &rjd2, &ns2);
632 c_find_ldom(y, m,
sg, &rjd2, &ns2);
635 *rjd = (rjd2 -
MOD((rjd2 - k) + 1, 7)) + 7 *
n;
636 *ns = (*rjd <
sg) ? 0 : 1;
643 return MOD(
jd + 1, 7);
648c_jd_to_nth_kday(
int jd,
double sg,
int *ry,
int *rm,
int *rn,
int *rk)
652 c_jd_to_civil(
jd,
sg, ry, rm, &rd);
653 c_find_fdom(*ry, *rm,
sg, &rjd, &ns2);
654 *rn =
DIV(
jd - rjd, 7) + 1;
655 *rk = c_jd_to_wday(
jd);
660c_valid_ordinal_p(
int y,
int d,
double sg,
661 int *rd,
int *rjd,
int *ns)
668 if (!c_find_ldoy(y,
sg, &rjd2, &ns2))
670 c_jd_to_ordinal(rjd2 + d + 1,
sg, &ry2, &rd2);
675 c_ordinal_to_jd(y, d,
sg, rjd, ns);
676 c_jd_to_ordinal(*rjd,
sg, &ry2, &rd2);
677 if (ry2 != y || rd2 != d)
682static const int monthtab[2][13] = {
683 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
684 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
688c_julian_leap_p(
int y)
690 return MOD(y, 4) == 0;
694c_gregorian_leap_p(
int y)
696 return (
MOD(y, 4) == 0 && y % 100 != 0) ||
MOD(y, 400) == 0;
700c_julian_last_day_of_month(
int y,
int m)
702 assert(m >= 1 && m <= 12);
703 return monthtab[c_julian_leap_p(y) ? 1 : 0][m];
707c_gregorian_last_day_of_month(
int y,
int m)
709 assert(m >= 1 && m <= 12);
710 return monthtab[c_gregorian_leap_p(y) ? 1 : 0][m];
714c_valid_julian_p(
int y,
int m,
int d,
int *rm,
int *rd)
722 last = c_julian_last_day_of_month(y, m);
725 if (d < 1 || d >
last)
733c_valid_gregorian_p(
int y,
int m,
int d,
int *rm,
int *rd)
741 last = c_gregorian_last_day_of_month(y, m);
744 if (d < 1 || d >
last)
752c_valid_civil_p(
int y,
int m,
int d,
double sg,
753 int *rm,
int *rd,
int *rjd,
int *ns)
760 if (!c_find_ldom(y, m,
sg, rjd, ns))
762 c_jd_to_civil(*rjd + d + 1,
sg, &ry, rm, rd);
763 if (ry != y || *rm != m)
767 c_civil_to_jd(y, m, d,
sg, rjd, ns);
768 c_jd_to_civil(*rjd,
sg, &ry, rm, rd);
769 if (ry != y || *rm != m || *rd != d)
775c_valid_commercial_p(
int y,
int w,
int d,
double sg,
776 int *rw,
int *rd,
int *rjd,
int *ns)
778 int ns2, ry2, rw2, rd2;
785 c_commercial_to_jd(y + 1, 1, 1,
sg, &rjd2, &ns2);
786 c_jd_to_commercial(rjd2 + w * 7,
sg, &ry2, &rw2, &rd2);
791 c_commercial_to_jd(y, w, d,
sg, rjd, ns);
792 c_jd_to_commercial(*rjd,
sg, &ry2, rw, rd);
793 if (y != ry2 || w != *rw || d != *rd)
799c_valid_weeknum_p(
int y,
int w,
int d,
int f,
double sg,
800 int *rw,
int *rd,
int *rjd,
int *ns)
802 int ns2, ry2, rw2, rd2;
809 c_weeknum_to_jd(y + 1, 1,
f,
f,
sg, &rjd2, &ns2);
810 c_jd_to_weeknum(rjd2 + w * 7,
f,
sg, &ry2, &rw2, &rd2);
815 c_weeknum_to_jd(y, w, d,
f,
sg, rjd, ns);
816 c_jd_to_weeknum(*rjd,
f,
sg, &ry2, rw, rd);
817 if (y != ry2 || w != *rw || d != *rd)
824c_valid_nth_kday_p(
int y,
int m,
int n,
int k,
double sg,
825 int *rm,
int *rn,
int *rk,
int *rjd,
int *ns)
827 int ns2, ry2, rm2, rn2, rk2;
838 c_nth_kday_to_jd(ny, nm, 1, k,
sg, &rjd2, &ns2);
839 c_jd_to_nth_kday(rjd2 +
n * 7,
sg, &ry2, &rm2, &rn2, &rk2);
840 if (ry2 != y || rm2 != m)
844 c_nth_kday_to_jd(y, m,
n, k,
sg, rjd, ns);
845 c_jd_to_nth_kday(*rjd,
sg, &ry2, rm, rn, rk);
846 if (y != ry2 || m != *rm ||
n != *rn || k != *rk)
853c_valid_time_p(
int h,
int min,
int s,
int *rh,
int *rmin,
int *rs)
864 return !(h < 0 || h > 24 ||
865 min < 0 || min > 59 ||
867 (
h == 24 && (min > 0 || s > 0)));
871c_valid_start_p(
double sg)
883df_local_to_utc(
int df,
int of)
894df_utc_to_local(
int df,
int of)
905jd_local_to_utc(
int jd,
int df,
int of)
916jd_utc_to_local(
int jd,
int df,
int of)
927time_to_df(
int h,
int min,
int s)
933df_to_time(
int df,
int *
h,
int *min,
int *s)
960 return f_quo(
n, day_in_nanoseconds);
990safe_mul_p(
VALUE x,
long m)
1020 return f_mul(d, day_in_nanoseconds);
1059 VALUE s = day_to_sec(d);
1083 *
jd = div_day(d, &
f);
1084 *
df = div_df(
f, &
f);
1093 if (f_zero_p(x->
s.
nth))
1095 else if (f_negative_p(x->
s.
nth))
1096 return positive_inf;
1097 return negative_inf;
1105 if (f_zero_p(x->
c.
nth))
1107 else if (f_negative_p(x->
c.
nth))
1108 return positive_inf;
1109 return negative_inf;
1116 return s_virtual_sg(x);
1118 return c_virtual_sg(x);
1121#define canonicalize_jd(_nth, _jd) \
1124 _nth = f_sub(_nth, INT2FIX(1));\
1127 if (_jd >= CM_PERIOD) {\
1128 _nth = f_add(_nth, INT2FIX(1));\
1142 x->
flags &= ~HAVE_CIVIL;
1154 c_civil_to_jd(x->
s.
year, x->
s.mon, x->
s.mday,
1155 s_virtual_sg(x), &
jd, &ns);
1158 s_virtual_sg(x), &
jd, &ns);
1173 c_jd_to_civil(x->
s.
jd, s_virtual_sg(x), &y, &m, &d);
1192 x->
c.
df = df_local_to_utc(time_to_df(x->
c.hour, x->
c.min, x->
c.sec),
1212 r = df_utc_to_local(x->
c.
df, x->
c.
of);
1213 df_to_time(r, &x->
c.hour, &x->
c.min, &x->
c.sec);
1216 int r, m, d,
h, min, s;
1221 r = df_utc_to_local(x->
c.
df, x->
c.
of);
1222 df_to_time(r, &
h, &min, &s);
1238 x->
flags &= ~HAVE_CIVIL;
1250 c_civil_to_jd(x->
c.
year, x->
c.mon, x->
c.mday,
1251 c_virtual_sg(x), &
jd, &ns);
1254 c_virtual_sg(x), &
jd, &ns);
1259 x->
c.
jd = jd_local_to_utc(
jd,
1260 time_to_df(x->
c.hour, x->
c.min, x->
c.sec),
1263 x->
c.
jd = jd_local_to_utc(
jd,
1281 int jd, y, m, d,
h, min, s;
1287 c_jd_to_civil(
jd, c_virtual_sg(x), &y, &m, &d);
1308 return jd_utc_to_local(x->
c.
jd, x->
c.
df, x->
c.
of);
1316 return df_utc_to_local(x->
c.
df, x->
c.
of);
1320decode_year(
VALUE y,
double style,
1326 period = (style < 0) ?
1336 inth =
DIV(it, ((
long)period));
1339 it =
MOD(it, ((
long)period));
1340 *ry = (
int)it - 4712;
1352encode_year(
VALUE nth,
int y,
double style,
1358 period = (style < 0) ?
1374 if (f_zero_p(*
nth)) {
1384 if (f_zero_p(
nth)) {
1392guess_style(
VALUE y,
double sg)
1405 style = positive_inf;
1407 style = negative_inf;
1417 canonicalize_s_jd(
obj, x);
1421 canonicalize_c_jd(
obj, x);
1458 encode_jd(
nth,
jd, &rjd);
1485 encode_jd(
nth,
jd, &rjd);
1504 return isec_to_day(m_df(x));
1521m_local_df_in_day(
union DateData *x)
1523 return isec_to_day(m_local_df(x));
1540 return ns_to_day(m_sf(x));
1547 return ns_to_sec(m_sf(x));
1561 fr = isec_to_day(
df);
1563 fr =
f_add(fr, ns_to_day(
sf));
1568#define HALF_DAYS_IN_SECONDS (DAY_IN_SECONDS / 2)
1594 r =
f_add(r, isec_to_day(
df));
1623 r =
f_add(r, isec_to_day(
df));
1645 return isec_to_day(m_of(x));
1668 sg = s_virtual_sg(x);
1673 sg = c_virtual_sg(x);
1676 return sg == positive_inf;
1683 return !m_julian_p(x);
1687m_proleptic_julian_p(
union DateData *x)
1698m_proleptic_gregorian_p(
union DateData *x)
1734 m_gregorian_p(x) ? -1 : +1,
1781static const int yeartab[2][13] = {
1782 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
1783 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
1787c_julian_to_yday(
int y,
int m,
int d)
1789 assert(m >= 1 && m <= 12);
1790 return yeartab[c_julian_leap_p(y) ? 1 : 0][m] + d;
1794c_gregorian_to_yday(
int y,
int m,
int d)
1796 assert(m >= 1 && m <= 12);
1797 return yeartab[c_gregorian_leap_p(y) ? 1 : 0][m] + d;
1807 sg = m_virtual_sg(x);
1809 if (m_proleptic_gregorian_p(x) ||
1811 return c_gregorian_to_yday(m_year(x), m_mon(x), m_mday(x));
1812 if (m_proleptic_julian_p(x))
1813 return c_julian_to_yday(m_year(x), m_mon(x), m_mday(x));
1814 c_jd_to_ordinal(
jd,
sg, &ry, &rd);
1821 return c_jd_to_wday(m_local_jd(x));
1829 c_jd_to_commercial(m_local_jd(x), m_virtual_sg(x),
1847 m_gregorian_p(x) ? -1 : +1,
1857 c_jd_to_commercial(m_local_jd(x), m_virtual_sg(x),
1878 c_jd_to_weeknum(m_local_jd(x),
f, m_virtual_sg(x),
1886 return m_wnumx(x, 0);
1892 return m_wnumx(x, 1);
1940#define decode_offset(of,s,h,m)\
1943 s = (of < 0) ? '-' : '+';\
1944 a = (of < 0) ? -of : of;\
1945 h = a / HOUR_IN_SECONDS;\
1946 m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
1963 return of2str(m_of(x));
1975 return f_kind_of_p(x, cDate);
1985k_rational_p(
VALUE x)
1991expect_numeric(
VALUE x)
1993 if (!k_numeric_p(x))
1999civil_to_jd(
VALUE y,
int m,
int d,
double sg,
2004 double style = guess_style(y,
sg);
2015 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2019 decode_year(y, style,
nth, ry);
2020 c_civil_to_jd(*ry, m, d, style, rjd, ns);
2027 int *ry,
int *rm,
int *rd)
2029 decode_jd(
jd,
nth, rjd);
2030 c_jd_to_civil(*rjd,
sg, ry, rm, rd);
2034ordinal_to_jd(
VALUE y,
int d,
double sg,
2039 double style = guess_style(y,
sg);
2050 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2054 decode_year(y, style,
nth, ry);
2055 c_ordinal_to_jd(*ry, d, style, rjd, ns);
2064 decode_jd(
jd,
nth, rjd);
2065 c_jd_to_ordinal(*rjd,
sg, ry, rd);
2069commercial_to_jd(
VALUE y,
int w,
int d,
double sg,
2074 double style = guess_style(y,
sg);
2079 c_commercial_to_jd(
FIX2INT(y), w, d,
sg, &
jd, ns);
2085 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2089 decode_year(y, style,
nth, ry);
2090 c_commercial_to_jd(*ry, w, d, style, rjd, ns);
2097 int *ry,
int *rw,
int *rd)
2099 decode_jd(
jd,
nth, rjd);
2100 c_jd_to_commercial(*rjd,
sg, ry, rw, rd);
2104weeknum_to_jd(
VALUE y,
int w,
int d,
int f,
double sg,
2109 double style = guess_style(y,
sg);
2120 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2124 decode_year(y, style,
nth, ry);
2125 c_weeknum_to_jd(*ry, w, d,
f, style, rjd, ns);
2132 int *ry,
int *rw,
int *rd)
2134 decode_jd(
jd,
nth, rjd);
2135 c_jd_to_weeknum(*rjd,
f,
sg, ry, rw, rd);
2139nth_kday_to_jd(
VALUE y,
int m,
int n,
int k,
double sg,
2144 double style = guess_style(y,
sg);
2155 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2159 decode_year(y, style,
nth, ry);
2160 c_nth_kday_to_jd(*ry, m,
n, k, style, rjd, ns);
2167 int *ry,
int *rm,
int *rn,
int *rk)
2169 decode_jd(
jd,
nth, rjd);
2170 c_jd_to_nth_kday(*rjd,
sg, ry, rm, rn, rk);
2175valid_ordinal_p(
VALUE y,
int d,
double sg,
2180 double style = guess_style(y,
sg);
2186 r = c_valid_ordinal_p(
FIX2INT(y), d,
sg, rd, &
jd, ns);
2194 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2198 decode_year(y, style,
nth, ry);
2199 r = c_valid_ordinal_p(*ry, d, style, rd, rjd, ns);
2205valid_gregorian_p(
VALUE y,
int m,
int d,
2209 decode_year(y, -1,
nth, ry);
2210 return c_valid_gregorian_p(*ry, m, d, rm, rd);
2214valid_civil_p(
VALUE y,
int m,
int d,
double sg,
2216 int *rm,
int *rd,
int *rjd,
2219 double style = guess_style(y,
sg);
2225 r = c_valid_civil_p(
FIX2INT(y), m, d,
sg, rm, rd, &
jd, ns);
2233 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2237 decode_year(y, style,
nth, ry);
2239 r = c_valid_gregorian_p(*ry, m, d, rm, rd);
2241 r = c_valid_julian_p(*ry, m, d, rm, rd);
2244 c_civil_to_jd(*ry, *rm, *rd, style, rjd, ns);
2250valid_commercial_p(
VALUE y,
int w,
int d,
double sg,
2252 int *rw,
int *rd,
int *rjd,
2255 double style = guess_style(y,
sg);
2261 r = c_valid_commercial_p(
FIX2INT(y), w, d,
sg, rw, rd, &
jd, ns);
2269 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2273 decode_year(y, style,
nth, ry);
2274 r = c_valid_commercial_p(*ry, w, d, style, rw, rd, rjd, ns);
2280valid_weeknum_p(
VALUE y,
int w,
int d,
int f,
double sg,
2282 int *rw,
int *rd,
int *rjd,
2285 double style = guess_style(y,
sg);
2291 r = c_valid_weeknum_p(
FIX2INT(y), w, d,
f,
sg, rw, rd, &
jd, ns);
2299 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2303 decode_year(y, style,
nth, ry);
2304 r = c_valid_weeknum_p(*ry, w, d,
f, style, rw, rd, rjd, ns);
2311valid_nth_kday_p(
VALUE y,
int m,
int n,
int k,
double sg,
2313 int *rm,
int *rn,
int *rk,
int *rjd,
2316 double style = guess_style(y,
sg);
2322 r = c_valid_nth_kday_p(
FIX2INT(y), m,
n, k,
sg, rm, rn, rk, &
jd, ns);
2330 decode_year(y, *ns ? -1 : +1, &nth2, ry);
2334 decode_year(y, style,
nth, ry);
2335 r = c_valid_nth_kday_p(*ry, m,
n, k, style, rm, rn, rk, rjd, ns);
2344offset_to_sec(
VALUE vof,
int *rof)
2346 int try_rational = 1;
2349 switch (
TYPE(vof)) {
2355 if (
n != -1 &&
n != 0 &&
n != 1)
2373 expect_numeric(vof);
2375 if (!k_rational_p(vof)) {
2386 vs = day_to_sec(vof);
2388 if (!k_rational_p(vs)) {
2399 if (!f_eqeq_p(vn, vs))
2430#define valid_sg(sg) \
2432 if (!c_valid_start_p(sg)) {\
2434 rb_warning("invalid start is ignored");\
2461 return valid_jd_sub(2, argv2,
klass, 1);
2499 int m, d, ry, rm, rd;
2509 if (!need_jd && (guess_style(y,
sg) < 0)) {
2510 if (!valid_gregorian_p(y, m, d,
2520 if (!valid_civil_p(y, m, d,
sg,
2527 encode_jd(
nth, rjd, &rjd2);
2536 VALUE vy, vm, vd, vsg;
2549 return valid_civil_sub(4, argv2,
klass, 1);
2571 VALUE vy, vm, vd, vsg;
2587 if (
NIL_P(valid_civil_sub(4, argv2,
klass, 0)))
2609 if (!valid_ordinal_p(y, d,
sg,
2616 encode_jd(
nth, rjd, &rjd2);
2637 return valid_ordinal_sub(3, argv2,
klass, 1);
2669 if (
NIL_P(valid_ordinal_sub(3, argv2,
klass, 0)))
2678 int w, d, ry, rw, rd;
2692 if (!valid_commercial_p(y, w, d,
sg,
2699 encode_jd(
nth, rjd, &rjd2);
2708 VALUE vy, vw, vd, vsg;
2721 return valid_commercial_sub(4, argv2,
klass, 1);
2739 VALUE vy, vw, vd, vsg;
2755 if (
NIL_P(valid_commercial_sub(4, argv2,
klass, 0)))
2765 int w, d,
f, ry, rw, rd;
2780 if (!valid_weeknum_p(y, w, d,
f,
sg,
2787 encode_jd(
nth, rjd, &rjd2);
2795 VALUE vy, vw, vd, vf, vsg;
2809 return valid_weeknum_sub(5, argv2,
klass, 1);
2815 VALUE vy, vw, vd, vf, vsg;
2829 if (
NIL_P(valid_weeknum_sub(5, argv2,
klass, 0)))
2838 int m,
n, k, ry, rm, rn, rk;
2851 if (!valid_nth_kday_p(y, m,
n, k,
sg,
2853 &rm, &rn, &rk, &rjd,
2858 encode_jd(
nth, rjd, &rjd2);
2866 VALUE vy, vm, vn, vk, vsg;
2880 return valid_nth_kday_sub(5, argv2,
klass, 1);
2886 VALUE vy, vm, vn, vk, vsg;
2900 if (
NIL_P(valid_nth_kday_sub(5, argv2,
klass, 0)))
2928 check_numeric(y,
"year");
2929 decode_year(y, +1, &
nth, &ry);
2950 check_numeric(y,
"year");
2951 decode_year(y, -1, &
nth, &ry);
2956d_lite_gc_mark(
void *
ptr)
2968d_lite_memsize(
const void *
ptr)
2985 int y,
int m,
int d,
3005 int y,
int m,
int d,
3006 int h,
int min,
int s,
3015 y, m, d,
h, min, s,
flags);
3026 return d_simple_new_internal(
klass,
3036 return d_complex_new_internal(
klass,
3048 return d_lite_s_alloc_complex(
klass);
3054 int *rof,
double *rsg)
3058 decode_day(
f_add(ajd, half_days_in_day),
3063 if (!f_eqeq_p(of2, t))
3066 decode_jd(
jd, rnth, rjd);
3074 rb_raise(eDateError,
"invalid day fraction");
3084 if (!c_valid_start_p(*rsg)) {
3109 old_to_new(ajd,
of,
sg,
3112 if (!
df && f_zero_p(
sf) && !rof)
3113 return d_simple_new_internal(
klass,
3119 return d_complex_new_internal(
klass,
3140 return round(d) == d;
3166 if (wholenum_p(d)) {
3177#define jd_trunc d_trunc
3178#define k_trunc d_trunc
3185 if (wholenum_p(
h)) {
3202 if (wholenum_p(min)) {
3203 rmin = to_integer(min);
3219 if (wholenum_p(s)) {
3231#define num2num_with_frac(s,n) \
3233 s = s##_trunc(v##s, &fr);\
3234 if (f_nonzero_p(fr)) {\
3236 rb_raise(eDateError, "invalid fraction");\
3241#define num2int_with_frac(s,n) \
3243 s = NUM2INT(s##_trunc(v##s, &fr));\
3244 if (f_nonzero_p(fr)) {\
3246 rb_raise(eDateError, "invalid fraction");\
3251#define canon24oc() \
3255 fr2 = f_add(fr2, INT2FIX(1));\
3261 if (f_nonzero_p(fr2))\
3262 ret = d_lite_plus(ret, fr2);\
3265#define val2sg(vsg,dsg) \
3267 dsg = NUM2DBL(vsg);\
3268 if (!c_valid_start_p(dsg)) {\
3270 rb_warning("invalid start is ignored");\
3292 VALUE vjd, vsg,
jd, fr, fr2, ret;
3305 check_numeric(vjd,
"jd");
3313 decode_jd(
jd, &
nth, &rjd);
3314 ret = d_simple_new_internal(
klass,
3343 VALUE vy, vd, vsg, y, fr, fr2, ret;
3358 check_numeric(vd,
"yday");
3361 check_numeric(vy,
"year");
3367 int ry, rd, rjd, ns;
3369 if (!valid_ordinal_p(y, d,
sg,
3373 rb_raise(eDateError,
"invalid date");
3375 ret = d_simple_new_internal(
klass,
3413 return date_initialize(
argc,
argv, d_lite_s_alloc_simple(
klass));
3419 VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
3440 check_numeric(vd,
"day");
3443 check_numeric(vm,
"month");
3446 check_numeric(vy,
"year");
3450 if (guess_style(y,
sg) < 0) {
3454 if (!valid_gregorian_p(y, m, d,
3457 rb_raise(eDateError,
"invalid date");
3463 int ry, rm, rd, rjd, ns;
3465 if (!valid_civil_p(y, m, d,
sg,
3469 rb_raise(eDateError,
"invalid date");
3497 VALUE vy, vw, vd, vsg, y, fr, fr2, ret;
3513 check_numeric(vd,
"cwday");
3516 check_numeric(vw,
"cweek");
3519 check_numeric(vy,
"year");
3525 int ry, rw, rd, rjd, ns;
3527 if (!valid_commercial_p(y, w, d,
sg,
3531 rb_raise(eDateError,
"invalid date");
3533 ret = d_simple_new_internal(
klass,
3547 VALUE vy, vw, vd, vf, vsg, y, fr, fr2, ret;
3575 int ry, rw, rd, rjd, ns;
3577 if (!valid_weeknum_p(y, w, d,
f,
sg,
3581 rb_raise(eDateError,
"invalid date");
3583 ret = d_simple_new_internal(
klass,
3596 VALUE vy, vm, vn, vk, vsg, y, fr, fr2, ret;
3624 int ry, rm, rn, rk, rjd, ns;
3626 if (!valid_nth_kday_p(y, m,
n, k,
sg,
3628 &rm, &rn, &rk, &rjd,
3630 rb_raise(eDateError,
"invalid date");
3632 ret = d_simple_new_internal(
klass,
3643#if !defined(HAVE_GMTIME_R)
3663static void set_sg(
union DateData *,
double);
3676 VALUE vsg, nth, ret;
3699 decode_year(
INT2FIX(y), -1, &nth, &ry);
3701 ret = d_simple_new_internal(
klass,
3713#define set_hash0(k,v) rb_hash_aset(hash, k, v)
3714#define ref_hash0(k) rb_hash_aref(hash, k)
3715#define del_hash0(k) rb_hash_delete(hash, k)
3717#define sym(x) ID2SYM(rb_intern(x""))
3719#define set_hash(k,v) set_hash0(sym(k), v)
3720#define ref_hash(k) ref_hash0(sym(k))
3721#define del_hash(k) del_hash0(sym(k))
3724rt_rewrite_frags(
VALUE hash)
3729 if (!
NIL_P(seconds)) {
3730 VALUE offset, d,
h, min, s, fr;
3734 seconds =
f_add(seconds, offset);
3863 long i, eno = 0, idx = 0;
3896 if (k ==
sym(
"ordinal")) {
3899 d = date_s_today(0, (
VALUE *)0, cDate);
3905 else if (k ==
sym(
"civil")) {
3914 d = date_s_today(0, (
VALUE *)0, cDate);
3922 else if (k ==
sym(
"commercial")) {
3931 d = date_s_today(0, (
VALUE *)0, cDate);
3939 else if (k ==
sym(
"wday")) {
3941 d = date_s_today(0, (
VALUE *)0, cDate);
3946 else if (k ==
sym(
"wnum0")) {
3955 d = date_s_today(0, (
VALUE *)0, cDate);
3963 else if (k ==
sym(
"wnum1")) {
3972 d = date_s_today(0, (
VALUE *)0, cDate);
3982 if (g && k ==
sym(
"time")) {
3985 d = date_s_today(0, (
VALUE *)0, cDate);
4013 int ry, rd, rjd, ns;
4020 encode_jd(nth, rjd, &rjd2);
4028 int ry, rm, rd, rjd, ns;
4035 encode_jd(nth, rjd, &rjd2);
4043 int ry, rw, rd, rjd, ns;
4050 encode_jd(nth, rjd, &rjd2);
4058 int ry, rw, rd, rjd, ns;
4065 encode_jd(nth, rjd, &rjd2);
4076 VALUE jd = rt__valid_jd_p(vjd, sg);
4087 VALUE jd = rt__valid_ordinal_p(year, yday, sg);
4094 VALUE year, mon, mday;
4099 VALUE jd = rt__valid_civil_p(year, mon, mday, sg);
4106 VALUE year, week, wday;
4119 VALUE jd = rt__valid_commercial_p(year, week, wday, sg);
4126 VALUE year, week, wday;
4132 if (f_eqeq_p(wday,
INT2FIX(7)))
4139 VALUE jd = rt__valid_weeknum_p(year, week, wday,
INT2FIX(0), sg);
4146 VALUE year, week, wday;
4158 VALUE jd = rt__valid_weeknum_p(year, week, wday,
INT2FIX(1), sg);
4171 if (!c_valid_start_p(
NUM2DBL(sg))) {
4177 rb_raise(eDateError,
"invalid date");
4184 jd = rt__valid_civil_p(
ref_hash(
"year"),
4188 hash = rt_rewrite_frags(hash);
4189 hash = rt_complete_frags(
klass, hash);
4190 jd = rt__valid_date_frags_p(hash, sg);
4194 rb_raise(eDateError,
"invalid date");
4199 decode_jd(jd, &nth, &rjd);
4200 return d_simple_new_internal(
klass,
4209 const char *
fmt,
size_t flen,
VALUE hash);
4213 const char *default_fmt)
4215 VALUE vstr, vfmt, hash;
4224 "string should have ASCII compatible encoding");
4229 flen =
strlen(default_fmt);
4235 "format should have ASCII compatible encoding");
4314 VALUE argv2[2], hash;
4318 hash = date_s__strptime(2, argv2,
klass);
4319 return d_new_by_frags(
klass, hash, sg);
4344 size_t limit = get_limit(opt);
4354 VALUE vstr, vcomp, hash, opt;
4358 check_limit(vstr, opt);
4362 "string should have ASCII compatible encoding");
4436 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4437 VALUE hash = date_s__parse(argc2, argv2,
klass);
4438 return d_new_by_frags(
klass, hash, sg);
4465 check_limit(
str, opt);
4504 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4505 VALUE hash = date_s__iso8601(argc2, argv2,
klass);
4506 return d_new_by_frags(
klass, hash, sg);
4526 check_limit(
str, opt);
4563 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4564 VALUE hash = date_s__rfc3339(argc2, argv2,
klass);
4565 return d_new_by_frags(
klass, hash, sg);
4585 check_limit(
str, opt);
4622 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4623 VALUE hash = date_s__xmlschema(argc2, argv2,
klass);
4624 return d_new_by_frags(
klass, hash, sg);
4645 check_limit(
str, opt);
4683 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4684 VALUE hash = date_s__rfc2822(argc2, argv2,
klass);
4685 return d_new_by_frags(
klass, hash, sg);
4705 check_limit(
str, opt);
4742 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4743 VALUE hash = date_s__httpdate(argc2, argv2,
klass);
4744 return d_new_by_frags(
klass, hash, sg);
4764 check_limit(
str, opt);
4805 if (!
NIL_P(opt)) argv2[argc2++] = opt;
4806 VALUE hash = date_s__jisx0301(argc2, argv2,
klass);
4807 return d_new_by_frags(
klass, hash, sg);
4838dup_obj_as_complex(
VALUE self)
4863#define val2off(vof,iof) \
4865 if (!offset_to_sec(vof, &iof)) {\
4867 rb_warning("invalid offset is ignored");\
4875 VALUE jd, vjd, vdf, sf, vsf, vof, vsg;
4898 rb_raise(eDateError,
"invalid second fraction");
4902 rb_raise(eDateError,
"invalid day fraction");
4913 decode_jd(jd, &nth, &rjd);
4914 if (!df && f_zero_p(sf) && !of) {
4920 "cannot load complex into simple");
4932d_lite_initialize_copy(
VALUE copy,
VALUE date)
4946 adat->c.nth = bdat->s.nth;
4947 adat->c.jd = bdat->s.jd;
4951 adat->c.sg = bdat->s.sg;
4952 adat->c.year = bdat->s.year;
4954 adat->c.mon = bdat->s.mon;
4955 adat->c.mday = bdat->s.mday;
4956 adat->c.hour = bdat->s.hour;
4957 adat->c.min = bdat->s.min;
4958 adat->c.sec = bdat->s.sec;
4960 adat->c.pc = bdat->s.pc;
4967 "cannot load complex into simple");
4977d_lite_fill(
VALUE self)
5006d_lite_ajd(
VALUE self)
5023d_lite_amjd(
VALUE self)
5040d_lite_jd(
VALUE self)
5043 return m_real_local_jd(dat);
5057d_lite_mjd(
VALUE self)
5073d_lite_ld(
VALUE self)
5089d_lite_year(
VALUE self)
5092 return m_real_year(dat);
5104d_lite_yday(
VALUE self)
5120d_lite_mon(
VALUE self)
5136d_lite_mday(
VALUE self)
5151d_lite_day_fraction(
VALUE self)
5169d_lite_cwyear(
VALUE self)
5172 return m_real_cwyear(dat);
5184d_lite_cweek(
VALUE self)
5199d_lite_cwday(
VALUE self)
5207d_lite_wnum0(
VALUE self)
5214d_lite_wnum1(
VALUE self)
5230d_lite_wday(
VALUE self)
5243d_lite_sunday_p(
VALUE self)
5256d_lite_monday_p(
VALUE self)
5269d_lite_tuesday_p(
VALUE self)
5282d_lite_wednesday_p(
VALUE self)
5295d_lite_thursday_p(
VALUE self)
5308d_lite_friday_p(
VALUE self)
5321d_lite_saturday_p(
VALUE self)
5335 if (
NUM2INT(k) != m_wday(dat))
5338 c_nth_kday_to_jd(m_year(dat), m_mon(dat),
5341 if (m_local_jd(dat) != rjd)
5356d_lite_hour(
VALUE self)
5372d_lite_min(
VALUE self)
5388d_lite_sec(
VALUE self)
5404d_lite_sec_fraction(
VALUE self)
5407 return m_sf_in_sec(dat);
5419d_lite_offset(
VALUE self)
5422 return m_of_in_day(dat);
5434d_lite_zone(
VALUE self)
5450d_lite_julian_p(
VALUE self)
5466d_lite_gregorian_p(
VALUE self)
5482d_lite_leap_p(
VALUE self)
5484 int rjd, ns, ry, rm, rd;
5487 if (m_gregorian_p(dat))
5488 return f_boolcast(c_gregorian_leap_p(m_year(dat)));
5490 c_civil_to_jd(m_year(dat), 3, 1, m_virtual_sg(dat),
5492 c_jd_to_civil(rjd - 1, m_virtual_sg(dat), &ry, &rm, &rd);
5506d_lite_start(
VALUE self)
5523 x->
s.
flags &= ~HAVE_CIVIL;
5541set_sg(
union DateData *x,
double sg)
5556dup_obj_with_new_start(
VALUE obj,
double sg)
5587 return dup_obj_with_new_start(
self, sg);
5597d_lite_italy(
VALUE self)
5599 return dup_obj_with_new_start(
self,
ITALY);
5609d_lite_england(
VALUE self)
5611 return dup_obj_with_new_start(
self,
ENGLAND);
5621d_lite_julian(
VALUE self)
5623 return dup_obj_with_new_start(
self,
JULIAN);
5633d_lite_gregorian(
VALUE self)
5635 return dup_obj_with_new_start(
self,
GREGORIAN);
5649dup_obj_with_new_offset(
VALUE obj,
int of)
5681 return dup_obj_with_new_offset(
self, rof);
5703 int try_rational = 1;
5707 switch (
TYPE(other)) {
5724 jd = m_jd(dat) + (
int)t;
5738 dat->c.df, dat->c.sf,
5739 dat->c.of, dat->c.
sg,
5777 jd = m_jd(dat) + jd;
5784 nth =
f_add(m_nth(dat), nth);
5796 dat->c.df, dat->c.sf,
5797 dat->c.of, dat->c.
sg,
5856 sf =
f_add(m_sf(dat), sf);
5870 df = m_df(dat) + df;
5884 jd = m_jd(dat) + jd;
5891 nth =
f_add(m_nth(dat), nth);
5893 if (!df && f_zero_p(sf) && !m_of(dat))
5905 m_of(dat), m_sg(dat),
5914 expect_numeric(other);
5916 if (!k_rational_p(other)) {
5927 if (wholenum_p(other)) {
5961 sf =
f_add(m_sf(dat), sf);
5975 df = m_df(dat) + df;
5989 jd = m_jd(dat) + jd;
5996 nth =
f_add(m_nth(dat), nth);
5998 if (!df && f_zero_p(sf) && !m_of(dat))
6010 m_of(dat), m_sg(dat),
6030 n =
f_sub(m_nth(adat), m_nth(bdat));
6031 d = m_jd(adat) - m_jd(bdat);
6032 df = m_df(adat) - m_df(bdat);
6033 sf =
f_sub(m_sf(adat), m_sf(bdat));
6062 r =
f_add(r, isec_to_day(df));
6064 r =
f_add(r, ns_to_day(sf));
6092 if (k_date_p(other))
6093 return minus_dd(
self, other);
6095 switch (
TYPE(other)) {
6101 expect_numeric(other);
6105 return d_lite_plus(
self,
f_negate(other));
6123 return d_lite_plus(
self,
n);
6140 return d_lite_minus(
self,
n);
6151d_lite_next(
VALUE self)
6153 return d_lite_next_day(0, (
VALUE *)
NULL,
self);
6182 VALUE t, y, nth, rjd2;
6207 if (valid_civil_p(y, m, d, sg,
6209 &rm, &rd, &rjd, &ns))
6212 rb_raise(eDateError,
"invalid date");
6214 encode_jd(nth, rjd, &rjd2);
6215 return d_lite_plus(
self,
f_sub(rjd2, m_real_local_jd(dat)));
6244 expect_numeric(other);
6245 return d_lite_rshift(
self,
f_negate(other));
6264 return d_lite_rshift(
self,
n);
6283 return d_lite_lshift(
self,
n);
6348 VALUE limit, step, date;
6366 while (
FIX2INT(d_lite_cmp(date, limit)) >= 0) {
6368 date = d_lite_plus(date, step);
6376 while (
FIX2INT(d_lite_cmp(date, limit)) <= 0) {
6378 date = d_lite_plus(date, step);
6399 while (
FIX2INT(d_lite_cmp(date, max)) <= 0) {
6401 date = d_lite_plus(date,
INT2FIX(1));
6421 while (
FIX2INT(d_lite_cmp(date, min)) >= 0) {
6423 date = d_lite_plus(date,
INT2FIX(-1));
6433 if (k_numeric_p(other))
6434 return INT2FIX(f_cmp(m_ajd(dat), other));
6435 else if (k_date_p(other))
6451 m_canonicalize_jd(
self, adat);
6452 m_canonicalize_jd(other, bdat);
6453 a_nth = m_nth(adat);
6454 b_nth = m_nth(bdat);
6455 if (f_eqeq_p(a_nth, b_nth)) {
6464 if (f_eqeq_p(a_sf, b_sf)) {
6467 else if (
f_lt_p(a_sf, b_sf)) {
6474 else if (a_df < b_df) {
6481 else if (a_jd < b_jd) {
6488 else if (
f_lt_p(a_nth, b_nth)) {
6516 if (!k_date_p(other))
6517 return cmp_gen(
self, other);
6523 m_gregorian_p(adat) == m_gregorian_p(bdat)))
6524 return cmp_dd(
self, other);
6530 m_canonicalize_jd(
self, adat);
6531 m_canonicalize_jd(other, bdat);
6532 a_nth = m_nth(adat);
6533 b_nth = m_nth(bdat);
6534 if (f_eqeq_p(a_nth, b_nth)) {
6540 else if (a_jd < b_jd) {
6547 else if (
f_lt_p(a_nth, b_nth)) {
6562 if (k_numeric_p(other))
6563 return f_eqeq_p(m_real_local_jd(dat), other);
6564 else if (k_date_p(other))
6565 return f_eqeq_p(m_real_local_jd(dat),
f_jd(other));
6589 if (!k_date_p(other))
6590 return equal_gen(
self, other);
6595 if (!(m_gregorian_p(adat) == m_gregorian_p(bdat)))
6596 return equal_gen(
self, other);
6602 m_canonicalize_jd(
self, adat);
6603 m_canonicalize_jd(other, bdat);
6604 a_nth = m_nth(adat);
6605 b_nth = m_nth(bdat);
6606 a_jd = m_local_jd(adat);
6607 b_jd = m_local_jd(bdat);
6608 if (f_eqeq_p(a_nth, b_nth) &&
6620 if (!k_date_p(other))
6622 return f_zero_p(d_lite_cmp(
self, other));
6627d_lite_hash(
VALUE self)
6641static void set_tmx(
VALUE,
struct tmx *);
6655d_lite_to_s(
VALUE self)
6657 return strftimev(
"%Y-%m-%d",
self, set_tmx);
6681 x->
s.
year, x->
s.mon, x->
s.mday,
6693 "%dy%dm%dd %dh%dm%ds; %s>",
6698 x->
c.
year, x->
c.mon, x->
c.mday,
6699 x->
c.hour, x->
c.min, x->
c.sec,
6711d_lite_inspect_raw(
VALUE self)
6725 m_real_jd(x), m_df(x), m_sf(x),
6741d_lite_inspect(
VALUE self)
6750size_t date_strftime(
char *s,
size_t maxsize,
const char *format,
6755date_strftime_alloc(
char **
buf,
const char *format,
6781 if (
size >= 1024 * flen) {
6795 s = day_to_sec(
f_sub(m_real_jd(x),
6805#define MILLISECOND_IN_NANOSECONDS 1000000
6812 s = sec_to_ms(tmx_m_secs(x));
6836 (
VALUE (*)(
void *))m_real_year,
6837 (
int (*)(
void *))m_yday,
6838 (
int (*)(
void *))m_mon,
6839 (
int (*)(
void *))m_mday,
6840 (
VALUE (*)(
void *))m_real_cwyear,
6841 (
int (*)(
void *))m_cweek,
6842 (
int (*)(
void *))m_cwday,
6843 (
int (*)(
void *))m_wnum0,
6844 (
int (*)(
void *))m_wnum1,
6845 (
int (*)(
void *))m_wday,
6846 (
int (*)(
void *))m_hour,
6847 (
int (*)(
void *))m_min,
6848 (
int (*)(
void *))m_sec,
6849 (
VALUE (*)(
void *))m_sf_in_sec,
6850 (
VALUE (*)(
void *))tmx_m_secs,
6851 (
VALUE (*)(
void *))tmx_m_msecs,
6852 (
int (*)(
void *))tmx_m_of,
6853 (
char *(*)(
void *))tmx_m_zone
6866 const char *default_fmt,
6884 "format should have ASCII compatible encoding");
6889 (*func)(
self, &
tmx);
6896 len = date_strftime_alloc(&
buf, p, &
tmx);
6899 if (
buf != buffer) {
6903 for (
fmt = p; p < pe && !*p; ++p);
7098 return date_strftime_internal(
argc,
argv,
self,
7099 "%Y-%m-%d", set_tmx);
7111 (*func)(
self, &
tmx);
7130d_lite_asctime(
VALUE self)
7132 return strftimev(
"%a %b %e %H:%M:%S %Y",
self, set_tmx);
7143d_lite_iso8601(
VALUE self)
7145 return strftimev(
"%Y-%m-%d",
self, set_tmx);
7155d_lite_rfc3339(
VALUE self)
7157 return strftimev(
"%Y-%m-%dT%H:%M:%S%:z",
self, set_tmx);
7168d_lite_rfc2822(
VALUE self)
7170 return strftimev(
"%a, %-d %b %Y %T %z",
self, set_tmx);
7181d_lite_httpdate(
VALUE self)
7183 volatile VALUE dup = dup_obj_with_new_offset(
self, 0);
7205 else if (d < 2424875) {
7209 else if (d < 2447535) {
7213 else if (d < 2458605) {
7236d_lite_jisx0301(
VALUE self)
7242 fmt = jisx0301_date_format(fmtbuf,
sizeof(fmtbuf),
7243 m_real_local_jd(
dat),
7250d_lite_marshal_dump_old(
VALUE self)
7272d_lite_marshal_dump(
VALUE self)
7313 VALUE ajd, vof, vsg;
7319 if (!k_numeric_p(vsg))
7328 old_to_new(ajd, vof, vsg,
7329 &nth, &jd, &df, &sf, &of, &sg);
7348 if (df || !f_zero_p(sf) || of) {
7378 return d_lite_marshal_load(
obj, a);
7398 VALUE vjd, vh, vmin, vs, vof, vsg, jd, fr, fr2, ret;
7417 check_numeric(vs,
"second");
7420 check_numeric(vmin,
"minute");
7423 check_numeric(vh,
"hour");
7426 check_numeric(vjd,
"jd");
7432 int rh, rmin, rs, rjd, rjd2;
7434 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7435 rb_raise(eDateError,
"invalid date");
7438 decode_jd(jd, &nth, &rjd);
7439 rjd2 = jd_local_to_utc(rjd,
7440 time_to_df(rh, rmin, rs),
7443 ret = d_complex_new_internal(
klass,
7470 VALUE vy, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7471 int d,
h, min, s, rof;
7490 check_numeric(vs,
"second");
7493 check_numeric(vmin,
"minute");
7496 check_numeric(vh,
"hour");
7499 check_numeric(vd,
"yday");
7502 check_numeric(vy,
"year");
7508 int ry, rd, rh, rmin, rs, rjd, rjd2, ns;
7510 if (!valid_ordinal_p(y, d, sg,
7514 rb_raise(eDateError,
"invalid date");
7515 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7516 rb_raise(eDateError,
"invalid date");
7519 rjd2 = jd_local_to_utc(rjd,
7520 time_to_df(rh, rmin, rs),
7523 ret = d_complex_new_internal(
klass,
7551 return datetime_initialize(
argc,
argv, d_lite_s_alloc_complex(
klass));
7557 VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7558 int m, d,
h, min, s, rof;
7566 rb_scan_args(
argc,
argv,
"08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
7583 check_numeric(vs,
"second");
7586 check_numeric(vmin,
"minute");
7589 check_numeric(vh,
"hour");
7592 check_numeric(vd,
"day");
7595 check_numeric(vm,
"month");
7598 check_numeric(vy,
"year");
7602 if (guess_style(y,
sg) < 0) {
7604 int ry, rm, rd, rh, rmin, rs;
7606 if (!valid_gregorian_p(y, m, d,
7609 rb_raise(eDateError,
"invalid date");
7610 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7611 rb_raise(eDateError,
"invalid date");
7624 int ry, rm, rd, rh, rmin, rs, rjd, rjd2, ns;
7626 if (!valid_civil_p(y, m, d,
sg,
7630 rb_raise(eDateError,
"invalid date");
7631 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7632 rb_raise(eDateError,
"invalid date");
7635 rjd2 = jd_local_to_utc(rjd,
7636 time_to_df(rh, rmin, rs),
7666 VALUE vy, vw, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7667 int w, d,
h, min, s, rof;
7670 rb_scan_args(
argc,
argv,
"08", &vy, &vw, &vd, &vh, &vmin, &vs, &vof, &vsg);
7687 check_numeric(vs,
"second");
7690 check_numeric(vmin,
"minute");
7693 check_numeric(vh,
"hour");
7696 check_numeric(vd,
"cwday");
7699 check_numeric(vw,
"cweek");
7702 check_numeric(vy,
"year");
7708 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7710 if (!valid_commercial_p(y, w, d,
sg,
7714 rb_raise(eDateError,
"invalid date");
7715 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7716 rb_raise(eDateError,
"invalid date");
7719 rjd2 = jd_local_to_utc(rjd,
7720 time_to_df(rh, rmin, rs),
7723 ret = d_complex_new_internal(
klass,
7739 VALUE vy, vw, vd, vf, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7740 int w, d,
f,
h, min, s, rof;
7744 &vh, &vmin, &vs, &vof, &vsg);
7779 int ry, rw, rd, rh, rmin, rs, rjd, rjd2, ns;
7781 if (!valid_weeknum_p(y, w, d,
f,
sg,
7785 rb_raise(eDateError,
"invalid date");
7786 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7787 rb_raise(eDateError,
"invalid date");
7790 rjd2 = jd_local_to_utc(rjd,
7791 time_to_df(rh, rmin, rs),
7793 ret = d_complex_new_internal(
klass,
7808 VALUE vy, vm, vn, vk, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7809 int m,
n, k,
h, min, s, rof;
7813 &vh, &vmin, &vs, &vof, &vsg);
7848 int ry, rm, rn, rk, rh, rmin, rs, rjd, rjd2, ns;
7850 if (!valid_nth_kday_p(y, m,
n, k,
sg,
7852 &rm, &rn, &rk, &rjd,
7854 rb_raise(eDateError,
"invalid date");
7855 if (!c_valid_time_p(
h, min, s, &rh, &rmin, &rs))
7856 rb_raise(eDateError,
"invalid date");
7859 rjd2 = jd_local_to_utc(rjd,
7860 time_to_df(rh, rmin, rs),
7862 ret = d_complex_new_internal(
klass,
7888#ifdef HAVE_CLOCK_GETTIME
7896 int y, ry, m, d,
h, min, s;
7905#ifdef HAVE_CLOCK_GETTIME
7926#ifdef HAVE_STRUCT_TM_TM_GMTOFF
7928#elif defined(HAVE_TIMEZONE)
7941#elif defined(HAVE_TIMEGM)
7960#ifdef HAVE_CLOCK_GETTIME
7963 sf = tv.tv_usec * 1000;
7971 decode_year(
INT2FIX(y), -1, &nth, &ry);
7973 ret = d_complex_new_internal(
klass,
7993 if (!c_valid_start_p(
NUM2DBL(sg))) {
7999 rb_raise(eDateError,
"invalid date");
8006 jd = rt__valid_civil_p(
ref_hash(
"year"),
8020 hash = rt_rewrite_frags(hash);
8021 hash = rt_complete_frags(
klass, hash);
8022 jd = rt__valid_date_frags_p(hash, sg);
8026 rb_raise(eDateError,
"invalid date");
8035 rb_raise(eDateError,
"invalid date");
8037 df = time_to_df(rh, rmin, rs);
8060 decode_jd(jd, &nth, &rjd);
8061 rjd2 = jd_local_to_utc(rjd, df, of);
8062 df = df_local_to_utc(df, of);
8064 return d_complex_new_internal(
klass,
8087 return date_s__strptime_internal(
argc,
argv,
klass,
"%FT%T%z");
8134 VALUE argv2[2], hash;
8138 hash = date_s__strptime(2, argv2,
klass);
8139 return dt_new_by_frags(
klass, hash, sg);
8187 if (!
NIL_P(opt)) argc2++;
8188 VALUE hash = date_s__parse(argc2, argv2,
klass);
8189 return dt_new_by_frags(
klass, hash, sg);
8231 if (!
NIL_P(opt)) argc2--;
8232 VALUE hash = date_s__iso8601(argc2, argv2,
klass);
8233 return dt_new_by_frags(
klass, hash, sg);
8271 if (!
NIL_P(opt)) argc2++;
8272 VALUE hash = date_s__rfc3339(argc2, argv2,
klass);
8273 return dt_new_by_frags(
klass, hash, sg);
8311 if (!
NIL_P(opt)) argc2++;
8312 VALUE hash = date_s__xmlschema(argc2, argv2,
klass);
8313 return dt_new_by_frags(
klass, hash, sg);
8352 if (!
NIL_P(opt)) argc2++;
8353 VALUE hash = date_s__rfc2822(argc2, argv2,
klass);
8354 return dt_new_by_frags(
klass, hash, sg);
8392 if (!
NIL_P(opt)) argc2++;
8393 VALUE hash = date_s__httpdate(argc2, argv2,
klass);
8394 return dt_new_by_frags(
klass, hash, sg);
8437 if (!
NIL_P(opt)) argc2++;
8438 VALUE hash = date_s__jisx0301(argc2, argv2,
klass);
8439 return dt_new_by_frags(
klass, hash, sg);
8454dt_lite_to_s(
VALUE self)
8456 return strftimev(
"%Y-%m-%dT%H:%M:%S%:z",
self, set_tmx);
8640 return date_strftime_internal(
argc,
argv,
self,
8641 "%Y-%m-%dT%H:%M:%S%:z", set_tmx);
8645iso8601_timediv(
VALUE self,
long n)
8647 static const char timefmt[] =
"T%H:%M:%S";
8648 static const char zone[] =
"%:z";
8653 memcpy(p, timefmt,
sizeof(timefmt)-1);
8654 p +=
sizeof(timefmt)-1;
8681 iso8601_timediv(
self,
n));
8697 return dt_lite_iso8601(
argc,
argv,
self);
8720 iso8601_timediv(
self,
n));
8725#define f_subsec(x) rb_funcall(x, rb_intern("subsec"), 0)
8726#define f_utc_offset(x) rb_funcall(x, rb_intern("utc_offset"), 0)
8727#define f_local3(x,y,m,d) rb_funcall(x, rb_intern("local"), 3, y, m, d)
8736time_to_time(
VALUE self)
8748time_to_date(
VALUE self)
8757 decode_year(y, -1, &nth, &ry);
8759 ret = d_simple_new_internal(cDate,
8778time_to_datetime(
VALUE self)
8780 VALUE y, sf, nth, ret;
8781 int ry, m, d,
h, min, s, of;
8796 decode_year(y, -1, &nth, &ry);
8798 ret = d_complex_new_internal(cDateTime,
8820date_to_time(
VALUE self)
8824 if (m_julian_p(adat)) {
8825 VALUE tmp = d_lite_gregorian(
self);
8843date_to_date(
VALUE self)
8855date_to_datetime(
VALUE self)
8860 VALUE new = d_lite_s_alloc_simple(cDateTime);
8868 VALUE new = d_lite_s_alloc_complex(cDateTime);
8895datetime_to_time(
VALUE self)
8897 volatile VALUE dup = dup_obj(
self);
8925datetime_to_date(
VALUE self)
8930 VALUE new = d_lite_s_alloc_simple(cDate);
8934 bdat->s.jd = m_local_jd(adat);
8939 VALUE new = d_lite_s_alloc_simple(cDate);
8943 bdat->s.jd = m_local_jd(adat);
8957datetime_to_datetime(
VALUE self)
8965#define MIN_YEAR -4713
8966#define MAX_YEAR 1000000
8968#define MAX_JD 366963925
8971test_civil(
int from,
int to,
double sg)
8976 from, to, to - from, sg);
8977 for (j = from; j <= to; j++) {
8978 int y, m, d, rj, ns;
8980 c_jd_to_civil(j, sg, &y, &m, &d);
8981 c_civil_to_jd(y, m, d, sg, &rj, &ns);
8993 if (!test_civil(MIN_JD, MIN_JD + 366,
GREGORIAN))
8995 if (!test_civil(2305814, 2598007,
GREGORIAN))
8997 if (!test_civil(MAX_JD - 366, MAX_JD,
GREGORIAN))
9000 if (!test_civil(MIN_JD, MIN_JD + 366,
ITALY))
9002 if (!test_civil(2305814, 2598007,
ITALY))
9004 if (!test_civil(MAX_JD - 366, MAX_JD,
ITALY))
9011test_ordinal(
int from,
int to,
double sg)
9016 from, to, to - from, sg);
9017 for (j = from; j <= to; j++) {
9020 c_jd_to_ordinal(j, sg, &y, &d);
9021 c_ordinal_to_jd(y, d, sg, &rj, &ns);
9033 if (!test_ordinal(MIN_JD, MIN_JD + 366,
GREGORIAN))
9035 if (!test_ordinal(2305814, 2598007,
GREGORIAN))
9037 if (!test_ordinal(MAX_JD - 366, MAX_JD,
GREGORIAN))
9040 if (!test_ordinal(MIN_JD, MIN_JD + 366,
ITALY))
9042 if (!test_ordinal(2305814, 2598007,
ITALY))
9044 if (!test_ordinal(MAX_JD - 366, MAX_JD,
ITALY))
9051test_commercial(
int from,
int to,
double sg)
9056 from, to, to - from, sg);
9057 for (j = from; j <= to; j++) {
9058 int y, w, d, rj, ns;
9060 c_jd_to_commercial(j, sg, &y, &w, &d);
9061 c_commercial_to_jd(y, w, d, sg, &rj, &ns);
9073 if (!test_commercial(MIN_JD, MIN_JD + 366,
GREGORIAN))
9075 if (!test_commercial(2305814, 2598007,
GREGORIAN))
9077 if (!test_commercial(MAX_JD - 366, MAX_JD,
GREGORIAN))
9080 if (!test_commercial(MIN_JD, MIN_JD + 366,
ITALY))
9082 if (!test_commercial(2305814, 2598007,
ITALY))
9084 if (!test_commercial(MAX_JD - 366, MAX_JD,
ITALY))
9091test_weeknum(
int from,
int to,
int f,
double sg)
9096 from, to, to - from, sg);
9097 for (j = from; j <= to; j++) {
9098 int y, w, d, rj, ns;
9100 c_jd_to_weeknum(j,
f, sg, &y, &w, &d);
9101 c_weeknum_to_jd(y, w, d,
f, sg, &rj, &ns);
9115 for (
f = 0;
f <= 1;
f++) {
9116 if (!test_weeknum(MIN_JD, MIN_JD + 366,
f,
GREGORIAN))
9118 if (!test_weeknum(2305814, 2598007,
f,
GREGORIAN))
9120 if (!test_weeknum(MAX_JD - 366, MAX_JD,
f,
GREGORIAN))
9123 if (!test_weeknum(MIN_JD, MIN_JD + 366,
f,
ITALY))
9125 if (!test_weeknum(2305814, 2598007,
f,
ITALY))
9127 if (!test_weeknum(MAX_JD - 366, MAX_JD,
f,
ITALY))
9135test_nth_kday(
int from,
int to,
double sg)
9140 from, to, to - from, sg);
9141 for (j = from; j <= to; j++) {
9142 int y, m,
n, k, rj, ns;
9144 c_jd_to_nth_kday(j, sg, &y, &m, &
n, &k);
9145 c_nth_kday_to_jd(y, m,
n, k, sg, &rj, &ns);
9157 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
GREGORIAN))
9159 if (!test_nth_kday(2305814, 2598007,
GREGORIAN))
9161 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
GREGORIAN))
9164 if (!test_nth_kday(MIN_JD, MIN_JD + 366,
ITALY))
9166 if (!test_nth_kday(2305814, 2598007,
ITALY))
9168 if (!test_nth_kday(MAX_JD - 366, MAX_JD,
ITALY))
9182 return f_eqeq_p(o,
i);
9189 if (!test_unit_v2v(
INT2FIX(0), conv1, conv2))
9191 if (!test_unit_v2v(
INT2FIX(1), conv1, conv2))
9193 if (!test_unit_v2v(
INT2FIX(2), conv1, conv2))
9195 if (!test_unit_v2v(
INT2FIX(3), conv1, conv2))
9197 if (!test_unit_v2v(
INT2FIX(11), conv1, conv2))
9199 if (!test_unit_v2v(
INT2FIX(65535), conv1, conv2))
9201 if (!test_unit_v2v(
INT2FIX(1073741823), conv1, conv2))
9203 if (!test_unit_v2v(
INT2NUM(1073741824), conv1, conv2))
9220 if (!test_unit_v2v_iter2(conv1, conv2))
9222 if (!test_unit_v2v_iter2(conv2, conv1))
9230 if (!test_unit_v2v_iter(sec_to_day, day_to_sec))
9232 if (!test_unit_v2v_iter(ms_to_sec, sec_to_ms))
9234 if (!test_unit_v2v_iter(ns_to_day, day_to_ns))
9236 if (!test_unit_v2v_iter(ns_to_sec, sec_to_ns))
9260static const char *monthnames[] = {
9262 "January",
"February",
"March",
9263 "April",
"May",
"June",
9264 "July",
"August",
"September",
9265 "October",
"November",
"December"
9268static const char *abbr_monthnames[] = {
9270 "Jan",
"Feb",
"Mar",
"Apr",
9271 "May",
"Jun",
"Jul",
"Aug",
9272 "Sep",
"Oct",
"Nov",
"Dec"
9275static const char *daynames[] = {
9276 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
9277 "Thursday",
"Friday",
"Saturday"
9280static const char *abbr_daynames[] = {
9281 "Sun",
"Mon",
"Tue",
"Wed",
9286mk_ary_of_str(
long len,
const char *a[])
9292 for (
i = 0;
i <
len;
i++) {
9317#define rb_intern(str) rb_intern_const(str)
9326#if (LONG_MAX / DAY_IN_SECONDS) > SECOND_IN_NANOSECONDS
9329#elif defined HAVE_LONG_LONG
9503 mk_ary_of_str(13, abbr_monthnames));
9513 rb_define_const(cDate,
"ABBR_DAYNAMES", mk_ary_of_str(7, abbr_daynames));
9539 date_s__valid_jd_p, -1);
9541 date_s__valid_ordinal_p, -1);
9543 date_s__valid_civil_p, -1);
9545 date_s__valid_civil_p, -1);
9547 date_s__valid_commercial_p, -1);
9549 date_s__valid_weeknum_p, -1);
9551 date_s__valid_nth_kday_p, -1);
9556 date_s_valid_ordinal_p, -1);
9560 date_s_valid_commercial_p, -1);
9564 date_s_valid_weeknum_p, -1);
9566 date_s_valid_nth_kday_p, -1);
9568 date_s_zone_to_diff, 1);
9573 date_s_gregorian_leap_p, 1);
9575 date_s_gregorian_leap_p, 1);
9871 datetime_s_commercial, -1);
9875 datetime_s_weeknum, -1);
9877 datetime_s_nth_kday, -1);
9884 datetime_s__strptime, -1);
9886 datetime_s_strptime, -1);
9888 datetime_s_parse, -1);
9890 datetime_s_iso8601, -1);
9892 datetime_s_rfc3339, -1);
9894 datetime_s_xmlschema, -1);
9896 datetime_s_rfc2822, -1);
9898 datetime_s_rfc2822, -1);
9900 datetime_s_httpdate, -1);
9902 datetime_s_jisx0301, -1);
9944 date_s_test_commercial, 0);
9948 date_s_test_unit_conv, 0);
#define MILLISECOND_IN_NANOSECONDS
#define val2off(vof, iof)
#define num2num_with_frac(s, n)
VALUE date__iso8601(VALUE)
VALUE date__rfc3339(VALUE)
#define copy_complex_to_simple(obj, x, y)
#define HALF_DAYS_IN_SECONDS
#define MINUTE_IN_SECONDS
#define set_to_complex(obj, x, _nth, _jd,_df, _sf, _of, _sg, _year, _mon, _mday, _hour, _min, _sec, _flags)
size_t date_strftime(char *s, size_t maxsize, const char *format, const struct tmx *tmx)
VALUE date__xmlschema(VALUE)
VALUE date__parse(VALUE str, VALUE comp)
#define REFORM_BEGIN_YEAR
#define SECOND_IN_NANOSECONDS
void Init_date_core(void)
#define UNIX_EPOCH_IN_CJD
VALUE date__strptime(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
#define num2int_with_frac(s, n)
#define PACK5(m, d, h, min, s)
VALUE date_zone_to_diff(VALUE)
#define set_to_simple(obj, x, _nth, _jd,_sg, _year, _mon, _mday, _flags)
#define decode_offset(of, s, h, m)
#define copy_simple_to_complex(obj, x, y)
VALUE date__jisx0301(VALUE)
#define RETURN_FALSE_UNLESS_NUMERIC(obj)
#define canonicalize_jd(_nth, _jd)
#define f_local3(x, y, m, d)
VALUE date__httpdate(VALUE)
VALUE date__rfc2822(VALUE)
#define SECOND_IN_MILLISECONDS
void rb_enc_copy(VALUE obj1, VALUE obj2)
rb_encoding * rb_usascii_encoding(void)
#define rb_enc_str_asciicompat_p(str)
#define rb_cmpint(cmp, a, b)
char str[HTML_ESCAPE_MAX_LEN+1]
void rb_include_module(VALUE, VALUE)
VALUE rb_define_class(const char *, VALUE)
Defines a top-level class.
VALUE rb_singleton_class(VALUE)
Returns the singleton class of obj.
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
void rb_undef_method(VALUE, const char *)
void rb_define_alias(VALUE, const char *, const char *)
Defines an alias of a method.
VALUE rb_cObject
Object class.
void rb_raise(VALUE exc, const char *fmt,...)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
void rb_sys_fail(const char *mesg)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
const struct tmx_funcs * funcs
#define strftimev(fmt, time, enc)
#define DECIMAL_SIZE_OF_BITS(n)
int gettimeofday(struct timeval *, struct timezone *)