13 #include <sys/types.h> 30 #if defined(HAVE_SYS_TIME_H) 39 #define NDIV(x,y) (-(-((x)+1)/(y))-1) 40 #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1) 41 #define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d)) 42 #define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d)) 57 if ((
long)x < (
long)y)
59 if ((
long)x > (
long)y)
66 #define ne(x,y) (!eq((x),(y))) 67 #define lt(x,y) (cmp((x),(y)) < 0) 68 #define gt(x,y) (cmp((x),(y)) > 0) 69 #define le(x,y) (cmp((x),(y)) <= 0) 70 #define ge(x,y) (cmp((x),(y)) >= 0) 96 #if !(HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG) 100 unsigned long a, b, c;
102 if (x == 0 || y == 0) {
108 a = (
unsigned long)-x;
112 a = (
unsigned long)x;
116 b = (
unsigned long)-y;
119 b = (
unsigned long)y;
121 if (a <= ULONG_MAX / b) {
124 if (c <= (
unsigned long)
LONG_MAX + 1) {
144 #if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG 160 #define div(x,y) (rb_funcall((x), id_div, 1, (y))) 171 #define neg(x) (sub(INT2FIX(0), (x))) 172 #define lshift(x,y) (rb_funcall((x), id_lshift, 1, (y))) 196 #define mulquo(x,y,z) (((y) == (z)) ? (x) : quo(mul((x),(y)),(z))) 213 # define INT64toNUM(x) LONG2NUM(x) 214 # define UINT64toNUM(x) ULONG2NUM(x) 215 #elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8 216 # define INT64toNUM(x) LL2NUM(x) 217 # define UINT64toNUM(x) ULL2NUM(x) 220 #if defined(HAVE_UINT64_T) && SIZEOF_LONG*2 <= SIZEOF_UINT64_T 225 # define WIDEVALUE_IS_WIDER 1 226 # define UWIDEINT_MAX UINT64_MAX 227 # define WIDEINT_MAX INT64_MAX 228 # define WIDEINT_MIN INT64_MIN 229 # define FIXWINT_P(tv) ((tv) & 1) 230 # define FIXWVtoINT64(tv) RSHIFT((SIGNED_WIDEVALUE)(tv), 1) 231 # define INT64toFIXWV(wi) ((WIDEVALUE)((SIGNED_WIDEVALUE)(wi) << 1 | FIXNUM_FLAG)) 232 # define FIXWV_MAX (((int64_t)1 << 62) - 1) 233 # define FIXWV_MIN (-((int64_t)1 << 62)) 234 # define FIXWVABLE(wi) (POSFIXWVABLE(wi) && NEGFIXWVABLE(wi)) 235 # define WINT2FIXWV(i) WIDEVAL_WRAP(INT64toFIXWV(i)) 236 # define FIXWV2WINT(w) FIXWVtoINT64(WIDEVAL_GET(w)) 242 # define WIDEVALUE_IS_WIDER 0 243 # define UWIDEINT_MAX ULONG_MAX 244 # define WIDEINT_MAX LONG_MAX 245 # define WIDEINT_MIN LONG_MIN 246 # define FIXWINT_P(v) FIXNUM_P(v) 247 # define FIXWV_MAX FIXNUM_MAX 248 # define FIXWV_MIN FIXNUM_MIN 249 # define FIXWVABLE(i) FIXABLE(i) 250 # define WINT2FIXWV(i) WIDEVAL_WRAP(LONG2FIX(i)) 251 # define FIXWV2WINT(w) FIX2LONG(WIDEVAL_GET(w)) 254 #define POSFIXWVABLE(wi) ((wi) < FIXWV_MAX+1) 255 #define NEGFIXWVABLE(wi) ((wi) >= FIXWV_MIN) 256 #define FIXWV_P(w) FIXWINT_P(WIDEVAL_GET(w)) 259 #ifdef STRUCT_WIDEVAL 265 # define WIDEVAL_GET(w) ((w).value) 268 # define WIDEVAL_WRAP(v) (v) 269 # define WIDEVAL_GET(w) (w) 272 #if WIDEVALUE_IS_WIDER 281 # define WINT2WV(wi) wint2wv(wi) 283 # define WINT2WV(wi) WIDEVAL_WRAP(LONG2NUM(wi)) 289 #if WIDEVALUE_IS_WIDER 298 #if WIDEVALUE_IS_WIDER 300 bdigit_find_maxbit(
BDIGIT d)
303 if (d & ~(
BDIGIT)0xffff) {
327 rb_big_abs_find_maxbit(
VALUE big)
333 while (0 <
len && ds[
len-1] == 0)
344 rb_big_abs_find_minbit(
VALUE big)
371 maxbit = rb_big_abs_find_maxbit(
v);
394 #if WIDEVALUE_IS_WIDER 400 return v2w_bignum(
v);
409 #if WIDEVALUE_IS_WIDER 423 #if WIDEVALUE_IS_WIDER 440 #define wne(x,y) (!weq((x),(y))) 441 #define wlt(x,y) (wcmp((x),(y)) < 0) 442 #define wgt(x,y) (wcmp((x),(y)) > 0) 443 #define wle(x,y) (wcmp((x),(y)) <= 0) 444 #define wge(x,y) (wcmp((x),(y)) >= 0) 450 #if WIDEVALUE_IS_WIDER 466 #if WIDEVALUE_IS_WIDER 483 if (x == 0 || y == 0) {
524 #if WIDEVALUE_IS_WIDER 544 #if WIDEVALUE_IS_WIDER 566 #define wmulquo(x,y,z) ((WIDEVAL_GET(y) == WIDEVAL_GET(z)) ? (x) : wquo(wmul((x),(y)),(z))) 567 #define wmulquoll(x,y,z) (((y) == (z)) ? (x) : wquo(wmul((x),WINT2WV(y)),WINT2WV(z))) 573 #if WIDEVALUE_IS_WIDER 720 #ifndef TYPEOF_TIMEVAL_TV_SEC 721 # define TYPEOF_TIMEVAL_TV_SEC time_t 723 #ifndef TYPEOF_TIMEVAL_TV_USEC 724 # if INT_MAX >= 1000000 725 # define TYPEOF_TIMEVAL_TV_USEC int 727 # define TYPEOF_TIMEVAL_TV_USEC long 731 #if SIZEOF_TIME_T == SIZEOF_LONG 733 #elif SIZEOF_TIME_T == SIZEOF_INT 735 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG 738 # error cannot find integer type which size is same as time_t. 741 #define TIMET_MAX (~(time_t)0 <= 0 ? (time_t)((~(unsigned_time_t)0) >> 1) : (time_t)(~(unsigned_time_t)0)) 742 #define TIMET_MIN (~(time_t)0 <= 0 ? (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0) 758 #if WIDEVALUE_IS_WIDER 776 #if WIDEVALUE_IS_WIDER 805 #if WIDEVALUE_IS_WIDER 819 return v2w(TIMET2NUM(t));
821 #define TIMET2WV(t) timet2wv(t) 826 #if WIDEVALUE_IS_WIDER 842 return NUM2TIMET(
w2v(w));
844 #define WV2TIMET(t) wv2timet(t) 860 static int tmcmp(
struct tm *a,
struct tm *b);
862 static const char *
find_time_t(
struct tm *tptr,
int utc_p, time_t *tp);
867 #define leap_year_v_p(y) leap_year_p(NUM2LONG(mod((y), INT2FIX(400)))) 870 #define rb_gmtime_r(t, tm) gmtime_r((t), (tm)) 871 #define rb_localtime_r(t, tm) localtime_r((t), (tm)) 873 static inline struct tm *
876 struct tm *t = gmtime(tp);
881 static inline struct tm *
884 struct tm *t = localtime(tp);
893 #if defined __APPLE__ && defined __LP64__ 894 if (*t != (time_t)(
int)*t)
return NULL;
897 #if defined(HAVE_MKTIME) && defined(LOCALTIME_OVERFLOW_PROBLEM) 903 # if defined(HAVE_STRUCT_TM_TM_GMTOFF) 904 gmtoff1 =
result->tm_gmtoff;
907 # if defined(HAVE_STRUCT_TM_TM_GMTOFF) 908 gmtoff2 = tmp.tm_gmtoff;
910 if (*t + gmtoff1 != t2 + gmtoff2)
916 #define LOCALTIME(tm, result) (tzset(),rb_localtime_r2((tm), &(result))) 918 #if !defined(HAVE_STRUCT_TM_TM_GMTOFF) 923 #if defined(HAVE_TIMEGM) && defined(LOCALTIME_OVERFLOW_PROBLEM) 926 time_t t2 = timegm(&tmp);
933 # define GMTIME(tm, result) rb_gmtime_r2((tm), &(result)) 941 -1 + 31 + 28 + 31 + 30,
942 -1 + 31 + 28 + 31 + 30 + 31,
943 -1 + 31 + 28 + 31 + 30 + 31 + 30,
944 -1 + 31 + 28 + 31 + 30 + 31 + 30 + 31,
945 -1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
946 -1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
947 -1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
948 -1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
956 -1 + 31 + 29 + 31 + 30,
957 -1 + 31 + 29 + 31 + 30 + 31,
958 -1 + 31 + 29 + 31 + 30 + 31 + 30,
959 -1 + 31 + 29 + 31 + 30 + 31 + 30 + 31,
960 -1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,
961 -1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
962 -1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
963 -1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
968 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
971 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
977 int tm_year_mod400 = (int)
MOD(tm_year, 400);
978 int tm_yday = tm_mday;
1017 +
DIV(year_mod400 - 69, 4)
1018 -
DIV(year_mod400 - 1, 100)
1019 + (year_mod400 + 299) / 400;
1041 return (
const char *)
v;
1055 const int *yday_offset;
1072 vtm->
sec = n % 60; n = n / 60;
1073 vtm->
min = n % 60; n = n / 60;
1090 if (30*365+7+31+29-1 <= n) {
1104 x = n / (365*100 + 24);
1105 n = n % (365*100 + 24);
1107 if (30*365+7+31+29-1 <= n) {
1117 x = n / (365*4 + 1);
1118 n = n % (365*4 + 1);
1120 if (365*2+31+29-1 <= n) {
1121 if (n < 365*2+366) {
1143 for (
i = 0;
i < 12;
i++) {
1144 if (yday_offset[
i] < n) {
1159 #if defined(HAVE_STRUCT_TM_TM_GMTOFF) 1163 int gmtoff_sec, gmtoff_min, gmtoff_hour, gmtoff_day;
1170 if (t->tm_gmtoff < 0) {
1172 gmtoff = -t->tm_gmtoff;
1176 gmtoff = t->tm_gmtoff;
1178 gmtoff_sec = (int)(gmtoff % 60);
1179 gmtoff = gmtoff / 60;
1180 gmtoff_min = (int)(gmtoff % 60);
1181 gmtoff = gmtoff / 60;
1182 gmtoff_hour = (int)gmtoff;
1186 gmtoff_hour *= sign;
1193 result->tm_sec += gmtoff_sec;
1194 if (
result->tm_sec < 0) {
1198 if (60 <=
result->tm_sec) {
1204 result->tm_min += gmtoff_min;
1205 if (
result->tm_min < 0) {
1209 if (60 <=
result->tm_min) {
1215 result->tm_hour += gmtoff_hour;
1216 if (
result->tm_hour < 0) {
1220 if (24 <=
result->tm_hour) {
1227 if (gmtoff_day < 0) {
1228 if (
result->tm_yday == 0) {
1234 else if (
result->tm_mday == 1) {
1250 if (
result->tm_yday == (leap ? 365 : 364)) {
1271 #if defined(HAVE_TM_ZONE) 1272 result->tm_zone = (
char *)
"UTC";
1303 if (
TIMET_MAX - now < (time_t)(366*86400))
1348 tm.tm_mon =
vtm->
mon - 1;
1389 result->mon = tm.tm_mon + 1;
1390 result->mday = tm.tm_mday;
1391 result->hour = tm.tm_hour;
1394 result->subsecx = subsecx;
1396 result->wday = tm.tm_wday;
1397 result->yday = tm.tm_yday+1;
1398 result->isdst = tm.tm_isdst;
1441 { 2034, 2035, 2036, 2031, 2032, 2027, 2033 },
1442 { 2026, 2027, 2033, 2034, 2035, 2030, 2031 },
1443 { 2026, 2032, 2033, 2034, 2035, 2030, 2036 },
1444 { 2035, 2030, 2036, 2026, 2032, 2033, 2034 },
1445 { 2033, 2034, 2035, 2030, 2036, 2026, 2032 },
1446 { 2036, 2026, 2032, 2033, 2034, 2035, 2030 },
1447 { 2035, 2030, 2036, 2026, 2032, 2033, 2034 },
1448 { 2032, 2033, 2034, 2035, 2030, 2036, 2026 },
1449 { 2030, 2036, 2026, 2032, 2033, 2034, 2035 },
1450 { 2034, 2035, 2030, 2036, 2026, 2032, 2033 },
1451 { 2026, 2032, 2033, 2034, 2035, 2030, 2036 },
1452 { 2030, 2036, 2026, 2032, 2033, 2034, 2035 },
1482 2032, 2016, 2028, 2012, 2024, 2036, 2020,
1491 a = (14 - month) / 12;
1492 y = year + 4800 - a;
1493 m = month + 12 * a - 3;
1494 wday = day + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 + 2;
1517 # if defined(NEGATIVE_TIME_T) 1518 # if SIZEOF_TIME_T <= 4 1520 # define THE_TIME_OLD_ENOUGH ((time_t)0x80000000) 1524 # define THE_TIME_OLD_ENOUGH ((time_t)(1600-1970)*366*24*60*60) 1528 isdst = tm.tm_isdst;
1535 isdst = tm.tm_isdst;
1558 t = NUM2TIMET(timev);
1562 *isdst_ret = tm.tm_isdst;
1570 static time_t now = 0;
1571 static long now_gmtoff = 0;
1572 static const char *now_zone =
"UTC";
1578 *isdst_ret = tm.tm_isdst;
1580 *zone_ret = now_zone;
1590 off = vtm1->
sec - vtm2->
sec;
1591 off += (vtm1->
min - vtm2->
min) * 60;
1592 off += (vtm1->
hour - vtm2->
hour) * 3600;
1594 off +=
lt(vtm1->
year, vtm2->
year) ? -24*3600 : 24*3600;
1595 else if (vtm1->
mon != vtm2->
mon)
1596 off += vtm1->
mon < vtm2->
mon ? -24*3600 : 24*3600;
1598 off += vtm1->
mday < vtm2->
mday ? -24*3600 : 24*3600;
1610 struct vtm vtm1, vtm2;
1615 if (l < INT_MIN || INT_MAX < l)
1617 tm.tm_year = (int)l;
1666 if (
weq(timew1, timew2))
1691 #if defined(HAVE_STRUCT_TM_TM_GMTOFF) 1692 *gmtoff = tm.tm_gmtoff;
1701 if (l->tm_year != u->tm_year)
1702 off = l->tm_year < u->tm_year ? -1 : 1;
1703 else if (l->tm_mon != u->tm_mon)
1704 off = l->tm_mon < u->tm_mon ? -1 : 1;
1705 else if (l->tm_mday != u->tm_mday)
1706 off = l->tm_mday < u->tm_mday ? -1 : 1;
1709 off = off * 24 + l->tm_hour - u->tm_hour;
1710 off = off * 60 + l->tm_min - u->tm_min;
1711 off = off * 60 + l->tm_sec - u->tm_sec;
1716 #if defined(HAVE_TM_ZONE) 1718 #elif defined(HAVE_TZNAME) && defined(HAVE_DAYLIGHT) 1724 strftime(
buf,
sizeof(
buf),
"%Z", &tm);
1740 #if WIDEVALUE_IS_WIDER && SIZEOF_TIME_T < SIZEOF_INT64_T 1749 timexv =
w2v(timew);
1775 result->mon = tm.tm_mon + 1;
1776 result->mday = tm.tm_mday;
1777 result->hour = tm.tm_hour;
1780 result->subsecx = subsecx;
1781 result->wday = tm.tm_wday;
1782 result->yday = tm.tm_yday+1;
1783 result->isdst = tm.tm_isdst;
1798 result->utc_offset = offset;
1812 #define GetTimeval(obj, tobj) ((tobj) = get_timeval(obj)) 1813 #define GetNewTimeval(obj, tobj) ((tobj) = get_new_timeval(obj)) 1815 #define IsTimeval(obj) rb_typeddata_is_kind_of((obj), &time_data_type) 1816 #define TIME_INIT_P(tobj) ((tobj)->gmt != -1) 1818 #define TIME_UTC_P(tobj) ((tobj)->gmt == 1) 1819 #define TIME_SET_UTC(tobj) ((tobj)->gmt = 1) 1821 #define TIME_LOCALTIME_P(tobj) ((tobj)->gmt == 0) 1822 #define TIME_SET_LOCALTIME(tobj) ((tobj)->gmt = 0) 1824 #define TIME_FIXOFF_P(tobj) ((tobj)->gmt == 2) 1825 #define TIME_SET_FIXOFF(tobj, off) \ 1827 (tobj)->vtm.utc_offset = (off), \ 1828 (tobj)->vtm.zone = NULL) 1830 #define TIME_COPY_GMT(tobj1, tobj2) \ 1831 ((tobj1)->gmt = (tobj2)->gmt, \ 1832 (tobj1)->vtm.utc_offset = (tobj2)->vtm.utc_offset, \ 1833 (tobj1)->vtm.zone = (tobj2)->vtm.zone) 1836 #define MAKE_TM(time, tobj) \ 1838 if ((tobj)->tm_got == 0) { \ 1839 time_get_tm((time), (tobj)); \ 1858 if (tobj)
xfree(tobj);
1978 #ifdef HAVE_CLOCK_GETTIME 1979 if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
2038 subsec =
neg(subsec);
2149 (s[0] !=
'+' && s[0] !=
'-') ||
2156 n = (s[1] * 10 + s[2] -
'0' * 11) * 3600;
2157 n += (s[4] * 10 + s[5] -
'0' * 11) * 60;
2290 time_t tmp, sec = *secp;
2293 if (nsec >= 1000000000) {
2294 tmp = sec + nsec / 1000000000;
2296 if (sec > 0 && tmp < 0) {
2302 tmp = sec +
NDIV(nsec,1000000000);
2303 nsec =
NMOD(nsec,1000000000);
2304 if (sec < 0 && tmp > 0) {
2309 #ifndef NEGATIVE_TIME_T 2345 if (usec >= 1000000) {
2346 long sec2 = usec / 1000000;
2350 usec -= sec2 * 1000000;
2353 else if (usec <= 1000000) {
2354 long sec2 = usec / 1000000;
2358 usec -= sec2 * 1000000;
2391 const char *tstr = interval ?
"time interval" :
"time";
2394 #ifndef NEGATIVE_TIME_T 2398 switch (
TYPE(num)) {
2400 t.
tv_sec = NUM2TIMET(num);
2401 if (interval && t.
tv_sec < 0)
2416 else if ((t.
tv_nsec = (
int)(-d*1e9+0.5)) > 0) {
2428 t.
tv_sec = NUM2TIMET(num);
2429 if (interval && t.
tv_sec < 0)
2441 if (interval && t.
tv_sec < 0)
2569 "jan",
"feb",
"mar",
"apr",
"may",
"jun",
2570 "jul",
"aug",
"sep",
"oct",
"nov",
"dec",
2630 for (
i=0;
i<12;
i++) {
2640 if (
'0' <= c && c <=
'9') {
2701 rb_scan_args(
argc,
argv,
"17", &
v[0],&
v[1],&
v[2],&
v[3],&
v[4],&
v[5],&
v[6],&
v[7]);
2743 return ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0);
2749 long tm_year = tm->tm_year;
2750 int tm_yday = tm->tm_mday;
2762 return tm->tm_sec + tm->tm_min*60 + tm->tm_hour*3600 +
2766 DIV(tm_year-1,100) +
2767 DIV(tm_year+299,400))*86400;
2771 #define DEBUG_FIND_TIME_NUMGUESS 2772 #define DEBUG_GUESSRANGE 2775 #ifdef DEBUG_GUESSRANGE 2776 #define DEBUG_REPORT_GUESSRANGE fprintf(stderr, "find time guess range: %ld - %ld : %lu\n", guess_lo, guess_hi, (unsigned_time_t)(guess_hi-guess_lo)) 2778 #define DEBUG_REPORT_GUESSRANGE 2781 #ifdef DEBUG_FIND_TIME_NUMGUESS 2782 #define DEBUG_FIND_TIME_NUMGUESS_INC find_time_numguess++, 2783 static unsigned long long find_time_numguess;
2785 static VALUE find_time_numguess_getter(
void)
2787 return ULL2NUM(find_time_numguess);
2790 #define DEBUG_FIND_TIME_NUMGUESS_INC 2796 time_t guess, guess0, guess_lo, guess_hi;
2797 struct tm *tm, tm0, tm_lo, tm_hi;
2804 #define GUESS(p) (DEBUG_FIND_TIME_NUMGUESS_INC (utc_p ? gmtime_with_leapsecond((p), &result) : LOCALTIME((p), result))) 2809 find_dst = 0 < tptr->tm_isdst;
2811 #if defined(HAVE_MKTIME) 2813 if (!utc_p && (guess = mktime(&tm0)) != -1) {
2815 if (tm &&
tmcmp(tptr, tm) == 0) {
2822 if (tm0.tm_mon < 0) {
2829 else if (11 < tm0.tm_mon) {
2836 else if (tm0.tm_mday < 1) {
2850 else if (tm0.tm_hour < 0) {
2855 else if (23 < tm0.tm_hour) {
2860 else if (tm0.tm_min < 0) {
2864 else if (59 < tm0.tm_min) {
2868 else if (tm0.tm_sec < 0) {
2871 else if (60 < tm0.tm_sec) {
2879 d =
tmcmp(tptr, tm);
2880 if (d == 0) {
goto found; }
2883 guess -= 24 * 60 * 60;
2887 guess += 24 * 60 * 60;
2890 if (guess_lo < guess && guess < guess_hi && (tm =
GUESS(&guess)) !=
NULL) {
2891 d =
tmcmp(tptr, tm);
2892 if (d == 0) {
goto found; }
2901 tm =
GUESS(&guess_lo);
2902 if (!tm)
goto error;
2903 d =
tmcmp(tptr, tm);
2904 if (d < 0)
goto out_of_range;
2905 if (d == 0) { guess = guess_lo;
goto found; }
2908 tm =
GUESS(&guess_hi);
2909 if (!tm)
goto error;
2910 d =
tmcmp(tptr, tm);
2911 if (d > 0)
goto out_of_range;
2912 if (d == 0) { guess = guess_hi;
goto found; }
2919 while (guess_lo + 1 < guess_hi) {
2922 guess = guess_lo / 2 + guess_hi / 2;
2923 if (guess <= guess_lo)
2924 guess = guess_lo + 1;
2925 else if (guess >= guess_hi)
2926 guess = guess_hi - 1;
2932 guess = guess_hi - (guess0_hi - guess0);
2933 if (guess == guess_hi)
2937 else if (status == 2) {
2939 guess = guess_lo + (guess0 - guess0_lo);
2940 if (guess == guess_lo)
2944 if (guess <= guess_lo || guess_hi <= guess) {
2946 #ifdef DEBUG_GUESSRANGE 2947 if (guess <= guess_lo) fprintf(stderr,
"too small guess: %ld <= %ld\n", guess, guess_lo);
2948 if (guess_hi <= guess) fprintf(stderr,
"too big guess: %ld <= %ld\n", guess_hi, guess);
2955 if (!tm)
goto error;
2957 d =
tmcmp(tptr, tm);
2975 guess2 = guess - 2 * 60 * 60;
2978 if (tptr->tm_hour != (tm->tm_hour + 2) % 24 ||
2979 tptr->tm_min != tm->tm_min ||
2980 tptr->tm_sec != tm->tm_sec) {
2981 guess2 -= (tm->tm_hour - tptr->tm_hour) * 60 * 60 +
2982 (tm->tm_min - tptr->tm_min) * 60 +
2983 (tm->tm_sec - tptr->tm_sec);
2984 if (tptr->tm_mday != tm->tm_mday)
2985 guess2 += 24 * 60 * 60;
2986 if (guess != guess2) {
2988 if (tm &&
tmcmp(tptr, tm) == 0) {
3000 guess2 = guess + 2 * 60 * 60;
3003 if ((tptr->tm_hour + 2) % 24 != tm->tm_hour ||
3004 tptr->tm_min != tm->tm_min ||
3005 tptr->tm_sec != tm->tm_sec) {
3006 guess2 -= (tm->tm_hour - tptr->tm_hour) * 60 * 60 +
3007 (tm->tm_min - tptr->tm_min) * 60 +
3008 (tm->tm_sec - tptr->tm_sec);
3009 if (tptr->tm_mday != tm->tm_mday)
3010 guess2 -= 24 * 60 * 60;
3011 if (guess != guess2) {
3013 if (tm &&
tmcmp(tptr, tm) == 0) {
3038 tptr_tm_yday =
calc_tm_yday(tptr->tm_year, tptr->tm_mon, tptr->tm_mday);
3041 ((tptr->tm_year - tm_lo.tm_year) * 365 +
3042 ((tptr->tm_year-69)/4) -
3043 ((tptr->tm_year-1)/100) +
3044 ((tptr->tm_year+299)/400) -
3045 ((tm_lo.tm_year-69)/4) +
3046 ((tm_lo.tm_year-1)/100) -
3047 ((tm_lo.tm_year+299)/400) +
3049 tm_lo.tm_yday) * 86400 +
3050 (tptr->tm_hour - tm_lo.tm_hour) * 3600 +
3051 (tptr->tm_min - tm_lo.tm_min) * 60 +
3052 (tptr->tm_sec - (tm_lo.tm_sec == 60 ? 59 : tm_lo.tm_sec));
3057 return "time out of range";
3060 return "gmtime/localtime error";
3068 else if (a->
mon != b->
mon)
3069 return a->
mon < b->
mon ? -1 : 1;
3074 else if (a->
min != b->
min)
3075 return a->
min < b->
min ? -1 : 1;
3076 else if (a->
sec != b->
sec)
3077 return a->
sec < b->
sec ? -1 : 1;
3087 if (a->tm_year != b->tm_year)
3088 return a->tm_year < b->tm_year ? -1 : 1;
3089 else if (a->tm_mon != b->tm_mon)
3090 return a->tm_mon < b->tm_mon ? -1 : 1;
3091 else if (a->tm_mday != b->tm_mday)
3092 return a->tm_mday < b->tm_mday ? -1 : 1;
3093 else if (a->tm_hour != b->tm_hour)
3094 return a->tm_hour < b->tm_hour ? -1 : 1;
3095 else if (a->tm_min != b->tm_min)
3096 return a->tm_min < b->tm_min ? -1 : 1;
3097 else if (a->tm_sec != b->tm_sec)
3098 return a->tm_sec < b->tm_sec ? -1 : 1;
3379 if (n == 0)
return INT2FIX(0);
3457 if (copy == time)
return copy;
3693 return strftimev(
"%a %b %e %T %Y", time);
3719 return strftimev(
"%Y-%m-%d %H:%M:%S UTC", time);
3721 return strftimev(
"%Y-%m-%d %H:%M:%S %z", time);
3815 rb_warn(
"Time#succ is obsolete; use time + 1");
3823 #define time_succ rb_time_succ 3865 VALUE ndigits,
v, a, b, den;
4054 #define wday_p(n) {\ 4055 struct time_object *tobj;\ 4056 GetTimeval(time, tobj);\ 4057 MAKE_TM(time, tobj);\ 4058 return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\ 4324 rb_strftime(
char *s,
size_t maxsize,
const char *format,
4328 #define SMALLBUF 100 4367 if (
size >= 1024 * flen) {
4582 rb_warning(
"strftime called with empty format string");
4584 else if (memchr(fmt,
'\0',
len)) {
4586 const char *
p = fmt, *pe = fmt +
len;
4593 if (
buf != buffer) {
4597 for (fmt =
p;
p < pe && !*
p; ++
p);
4636 if (
year < 1900 || 1900+0xffff <
year)
4663 for (
i=0;
i<4;
i++) {
4664 buf[
i] = (
unsigned char)
p;
4667 for (
i=4;
i<8;
i++) {
4668 buf[
i] = (
unsigned char)s;
4693 int len = (int)
sizeof(
buf);
4694 buf[1] = (char)((nsec % 10) << 4);
4696 buf[0] = (char)(nsec % 10);
4698 buf[0] |= (char)((nsec % 10) << 4);
4746 VALUE submicro, nano_num, nano_den, offset;
4752 #define get_attr(attr, iffound) \ 4753 attr = rb_attr_get(str, id_##attr); \ 4754 if (!NIL_P(attr)) { \ 4757 st_delete(rb_generic_ivar_table(str), &data, 0); \ 4775 for (
i=0;
i<4;
i++) {
4778 for (
i=4;
i<8;
i++) {
4779 s |=
buf[
i]<<(8*(
i-4));
4782 if ((
p & (1UL<<31)) == 0) {
4792 gmt = (int)((
p >> 30) & 0x1);
4795 vtm.
mon = ((int)(
p >> 10) & 0xf) + 1;
4798 vtm.
min = (int)(s >> 26) & 0x3f;
4799 vtm.
sec = (int)(s >> 20) & 0x3f;
4805 usec = (
long)(s & 0xfffff);
4810 if (nano_num !=
Qnil) {
4814 else if (submicro !=
Qnil) {
4822 if (10 <= (
digit = ptr[0] >> 4))
goto end_submicro;
4823 nsec +=
digit * 100;
4824 if (10 <= (
digit = ptr[0] & 0xf))
goto end_submicro;
4828 if (10 <= (
digit = ptr[1] >> 4))
goto end_submicro;
4840 tobj->
timew = timew;
4844 else if (!
NIL_P(offset)) {
4889 #define rb_intern(str) rb_intern_const(str) 4989 #ifdef DEBUG_FIND_TIME_NUMGUESS static const rb_data_type_t time_data_type
VALUE rb_big_modulo(VALUE x, VALUE y)
#define RSTRING_LEN(string)
static long NUM2LONG(VALUE x)
static VALUE quo(VALUE x, VALUE y)
static int cmp(VALUE x, VALUE y)
static int vtmcmp(struct vtm *a, struct vtm *b)
static time_t timegm_noleapsecond(struct tm *tm)
static VALUE w2v(wideval_t w)
static VALUE time_mon(VALUE time)
static VALUE time_to_r(VALUE time)
VALUE rb_ary_entry(VALUE ary, long offset)
int gettimeofday(struct timeval *, struct timezone *)
void rb_enc_copy(VALUE obj1, VALUE obj2)
static int obj2int(VALUE obj)
static VALUE time_sunday(VALUE time)
static VALUE time_getlocaltime(int argc, VALUE *argv, VALUE time)
size_t strlen(const char *)
static struct timespec * timew2timespec_exact(wideval_t timew, struct timespec *ts)
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
static VALUE time_s_now(VALUE klass)
static VALUE time_utc_or_local(int argc, VALUE *argv, int utc_p, VALUE klass)
static int tmcmp(struct tm *a, struct tm *b)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE time_utc_p(VALUE time)
static struct time_object * get_new_timeval(VALUE obj)
#define GetTimeval(obj, tobj)
static wideval_t timelocalw(struct vtm *vtm)
VALUE rb_str_cat(VALUE, const char *, long)
static void split_second(wideval_t timew, wideval_t *timew_p, VALUE *subsecx_p)
#define RFLOAT_VALUE(val)
static VALUE obj2vint(VALUE obj)
static VALUE time_minus(VALUE time1, VALUE time2)
static VALUE small_vtm_sub(struct vtm *vtm1, struct vtm *vtm2)
static VALUE time_hash(VALUE time)
static VALUE time_localtime_m(int argc, VALUE *argv, VALUE time)
static VALUE time_s_alloc(VALUE klass)
static VALUE time_utc_offset _((VALUE))
#define TypedData_Get_Struct(obj, type, data_type, sval)
static VALUE time_get_tm(VALUE, struct time_object *)
static int calc_tm_yday(long tm_year, int tm_mon, int tm_mday)
VALUE rb_big_plus(VALUE x, VALUE y)
static VALUE time_sec(VALUE time)
struct timeval rb_time_interval(VALUE num)
size_t rb_strftime_timespec(char *s, size_t maxsize, const char *format, const struct vtm *vtm, struct timespec *ts, int gmt)
static int leap_year_p(long y)
#define DEBUG_REPORT_GUESSRANGE
static struct tm * localtime_with_gmtoff_zone(const time_t *t, struct tm *result, long *gmtoff, const char **zone)
static VALUE time_gmtime(VALUE)
static VALUE time_monday(VALUE time)
static VALUE INT2NUM(int v)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static const int common_year_days_in_month[]
VALUE rb_time_succ(VALUE time)
#define RSTRING_PTR(string)
#define TYPEOF_TIMEVAL_TV_USEC
static VALUE time_init(int argc, VALUE *argv, VALUE time)
void rb_raise(VALUE exc, const char *fmt,...)
static void vtm_add_offset(struct vtm *vtm, VALUE off)
static VALUE time_round(int argc, VALUE *argv, VALUE time)
static VALUE add(VALUE x, VALUE y)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static VALUE time_plus(VALUE time1, VALUE time2)
static wideval_t wsub(wideval_t wx, wideval_t wy)
VALUE rb_ary_new3(long n,...)
void rb_include_module(VALUE klass, VALUE module)
static VALUE time_utc_offset(VALUE time)
void rb_gc_mark(VALUE ptr)
static VALUE time_usec(VALUE time)
static int long_mul(long x, long y, long *z)
static int compat_leap_month_table[7]
#define TIME_LOCALTIME_P(tobj)
static VALUE time_init_0(VALUE time)
static struct tm * rb_localtime_r2(const time_t *t, struct tm *result)
static size_t time_memsize(const void *tobj)
unsigned long unsigned_time_t
static wideval_t wadd(wideval_t wx, wideval_t wy)
static VALUE time_mload(VALUE time, VALUE str)
static VALUE time_wednesday(VALUE time)
VALUE rb_check_to_integer(VALUE, const char *)
static VALUE time_min(VALUE time)
static VALUE time_cmp(VALUE time1, VALUE time2)
static int min(int a, int b)
int rb_cmpint(VALUE val, VALUE a, VALUE b)
static VALUE time_yday(VALUE time)
const char * rb_obj_classname(VALUE)
static int number_of_leap_seconds_known
static VALUE time_add(struct time_object *tobj, VALUE offset, int sign)
static VALUE time_new_timew(VALUE klass, wideval_t timew)
VALUE rb_obj_untaint(VALUE)
static struct tm * rb_gmtime_r2(const time_t *t, struct tm *result)
static time_t wv2timet(wideval_t w)
static VALUE time_wday(VALUE time)
static wideval_t nsec2timew(time_t sec, long nsec)
static const char * find_time_t(struct tm *tptr, int utc_p, time_t *tp)
static VALUE time_asctime(VALUE time)
static VALUE time_s_at(int argc, VALUE *argv, VALUE klass)
static VALUE time_set_utc_offset(VALUE time, VALUE off)
unsigned long long uint64_t
#define GetNewTimeval(obj, tobj)
static wideval_t wmod(wideval_t wx, wideval_t wy)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
static VALUE time_load(VALUE klass, VALUE str)
RUBY_EXTERN VALUE rb_cObject
#define get_attr(attr, iffound)
VALUE rb_time_new(time_t sec, long usec)
#define wmulquoll(x, y, z)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
#define TIME_SET_UTC(tobj)
static int obj2subsecx(VALUE obj, VALUE *subsecx)
static VALUE mod(VALUE x, VALUE y)
#define LOCALTIME(tm, result)
static VALUE time_saturday(VALUE time)
#define TIME_FIXOFF_P(tobj)
static int wcmp(wideval_t wx, wideval_t wy)
static VALUE time_subsec(VALUE time)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static struct vtm * localtimew(wideval_t timew, struct vtm *result)
static void time_arg(int argc, VALUE *argv, struct vtm *vtm)
static wideval_t wdiv(wideval_t wx, wideval_t wy)
#define GMTIME(tm, result)
static const char * zone_str(const char *s)
static int calc_wday(int year, int month, int day)
static wideval_t wmul(wideval_t wx, wideval_t wy)
#define TIME_INIT_P(tobj)
static VALUE time_eql(VALUE time1, VALUE time2)
#define MEMCPY(p1, p2, type, n)
static struct tm * rb_gmtime_r(const time_t *tp, struct tm *result)
void rb_num_zerodiv(void)
static VALUE guess_local_offset(struct vtm *vtm_utc, int *isdst_ret, const char **zone_ret)
static int weq(wideval_t wx, wideval_t wy)
#define RBIGNUM_DIGITS(b)
static VALUE time_localtime(VALUE)
static VALUE time_mday(VALUE time)
static void gmtimew_noleapsecond(wideval_t timew, struct vtm *vtm)
static VALUE utc_offset_arg(VALUE arg)
static VALUE time_to_i(VALUE time)
static void divmodv(VALUE n, VALUE d, VALUE *q, VALUE *r)
VALUE rb_big_minus(VALUE x, VALUE y)
static VALUE time_to_s(VALUE time)
VALUE rb_locale_str_new_cstr(const char *)
static VALUE time_to_f(VALUE time)
static const int leap_year_yday_offset[]
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
static VALUE time_getgmtime(VALUE time)
static struct tm * rb_localtime_r(const time_t *tp, struct tm *result)
static void validate_vtm(struct vtm *vtm)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define TIME_COPY_GMT(tobj1, tobj2)
static void time_free(void *tobj)
unsigned char buf[MIME_BUF_SIZE]
static wideval_t rb_time_magnify(wideval_t w)
static VALUE time_fixoff(VALUE)
static VALUE num_exact(VALUE v)
VALUE rb_big_mul(VALUE x, VALUE y)
static VALUE time_init_1(int argc, VALUE *argv, VALUE time)
static int wi_mul(wideint_t x, wideint_t y, wideint_t *z)
static st_table * zone_table
#define rb_enc_str_asciicompat_p(str)
static struct timespec time_timespec(VALUE num, int interval)
static void validate_utc_offset(VALUE utc_offset)
static VALUE sub(VALUE x, VALUE y)
register unsigned int len
VALUE rb_time_nano_new(time_t sec, long nsec)
static int timew_out_of_timet_range(wideval_t timew)
static size_t rb_strftime_alloc(char **buf, const char *format, struct vtm *vtm, wideval_t timew, int gmt)
static VALUE mul(VALUE x, VALUE y)
void rb_sys_fail(const char *mesg)
static struct vtm * gmtimew(wideval_t timew, struct vtm *result)
static long usec2subsecx(VALUE obj)
static int month_arg(VALUE arg)
static VALUE time_tuesday(VALUE time)
static wideval_t rb_time_unmagnify(wideval_t w)
static wideval_t v2w(VALUE v)
static VALUE time_to_a(VALUE time)
static VALUE time_thursday(VALUE time)
int rb_respond_to(VALUE, ID)
static const int common_year_yday_offset[]
static struct timeval time_timeval(VALUE num, int interval)
static VALUE time_strftime(VALUE time, VALUE format)
static wideval_t timegmw_noleapsecond(struct vtm *vtm)
static VALUE time_hour(VALUE time)
static time_t known_leap_seconds_limit
VALUE rb_equal(VALUE, VALUE)
static VALUE strftimev(const char *fmt, VALUE time)
#define TYPEOF_TIMEVAL_TV_SEC
#define TIME_SET_LOCALTIME(tobj)
static void init_leap_second_info()
static VALUE time_mdump(VALUE time)
static void time_mark(void *ptr)
VALUE rb_check_array_type(VALUE ary)
#define TIME_SET_FIXOFF(tobj, off)
static VALUE time_isdst(VALUE time)
static VALUE time_dup(VALUE time)
static VALUE time_s_mkutc(int argc, VALUE *argv, VALUE klass)
static wideval_t timespec2timew(struct timespec *ts)
#define MAKE_TM(time, tobj)
VALUE rb_check_string_type(VALUE)
static struct tm * gmtime_with_leapsecond(const time_t *timep, struct tm *result)
struct timespec rb_time_timespec(VALUE time)
size_t rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, int gmt)
static void wmuldivmod(wideval_t wx, wideval_t wy, wideval_t wz, wideval_t *wq, wideval_t *wr)
static int compat_common_month_table[12][7]
static void time_overflow_p(time_t *secp, long *nsecp)
SIGNED_VALUE SIGNED_WIDEVALUE
#define TypedData_Make_Struct(klass, type, data_type, sval)
static VALUE time_friday(VALUE time)
static const int leap_year_days_in_month[]
static void wdivmod(wideval_t wn, wideval_t wd, wideval_t *wq, wideval_t *wr)
static struct timespec timew2timespec(wideval_t timew)
#define StringValuePtr(v)
static VALUE time_zone(VALUE time)
#define STRCASECMP(s1, s2)
void rb_warning(const char *fmt,...)
static wideval_t timet2wv(time_t t)
#define rb_check_frozen(obj)
static void time_modify(VALUE time)
static VALUE time_s_mktime(int argc, VALUE *argv, VALUE klass)
void rb_copy_generic_ivar(VALUE, VALUE)
#define RBIGNUM_NEGATIVE_P(b)
static VALUE time_year(VALUE time)
static VALUE rb_time_unmagnify_to_float(wideval_t w)
static VALUE time_init_copy(VALUE copy, VALUE time)
static VALUE time_nsec(VALUE time)
static const char months[][4]
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static struct time_object * get_timeval(VALUE obj)
static int eq(VALUE x, VALUE y)
void rb_warn(const char *fmt,...)
static VALUE time_dump(int argc, VALUE *argv, VALUE time)
struct timeval rb_time_timeval(VALUE time)
VALUE rb_str_new(const char *, long)
VALUE rb_obj_class(VALUE)
static wideval_t timegmw(struct vtm *vtm)
VALUE rb_time_num_new(VALUE timev, VALUE off)
static wideval_t wquo(wideval_t wx, wideval_t wy)