10 static const char *day_names[] = {
11 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
12 "Thursday",
"Friday",
"Saturday",
13 "Sun",
"Mon",
"Tue",
"Wed",
17 static const char *month_names[] = {
18 "January",
"February",
"March",
"April",
19 "May",
"June",
"July",
"August",
"September",
20 "October",
"November",
"December",
21 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
22 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 25 static const char *merid_names[] = {
30 static const char *extz_pats[] = {
36 #define sizeof_array(o) (sizeof o / sizeof o[0]) 38 #define f_negate(x) rb_funcall(x, rb_intern("-@"), 0) 39 #define f_add(x,y) rb_funcall(x, '+', 1, y) 40 #define f_sub(x,y) rb_funcall(x, '-', 1, y) 41 #define f_mul(x,y) rb_funcall(x, '*', 1, y) 42 #define f_div(x,y) rb_funcall(x, '/', 1, y) 43 #define f_idiv(x,y) rb_funcall(x, rb_intern("div"), 1, y) 44 #define f_mod(x,y) rb_funcall(x, '%', 1, y) 45 #define f_expt(x,y) rb_funcall(x, rb_intern("**"), 1, y) 47 #define f_lt_p(x,y) rb_funcall(x, '<', 1, y) 48 #define f_gt_p(x,y) rb_funcall(x, '>', 1, y) 49 #define f_le_p(x,y) rb_funcall(x, rb_intern("<="), 1, y) 50 #define f_ge_p(x,y) rb_funcall(x, rb_intern(">="), 1, y) 52 #define f_match(r,s) rb_funcall(r, rb_intern("match"), 1, s) 53 #define f_aref(o,i) rb_funcall(o, rb_intern("[]"), 1, i) 54 #define f_end(o,i) rb_funcall(o, rb_intern("end"), 1, i) 56 #define issign(c) ((c) == '-' || (c) == '+') 59 num_pattern_p(
const char *s)
61 if (isdigit((
unsigned char)*s))
65 if (*s ==
'E' || *s ==
'O')
68 (
strchr(
"CDdeFGgHIjkLlMmNQRrSsTUuVvWwXxYy", *s) ||
69 isdigit((
unsigned char)*s)))
75 #define NUM_PATTERN_P() num_pattern_p(&fmt[fi + 1]) 78 read_digits(
const char *s,
VALUE *n,
size_t width)
82 l = strspn(s,
"0123456789");
90 if ((4 * l *
sizeof(
char)) <= (
sizeof(
long)*
CHAR_BIT)) {
95 while ((
size_t)(s - os) < l) {
107 char *s2 =
ALLOCV_N(
char, vbuf, l + 1);
116 #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v) 117 #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k))) 118 #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k))) 122 set_hash("_fail", Qtrue); \ 126 #define fail_p() (!NIL_P(ref_hash("_fail"))) 128 #define READ_DIGITS(n,w) \ 131 l = read_digits(&str[si], &n, w); \ 137 #define READ_DIGITS_MAX(n) READ_DIGITS(n, LONG_MAX) 140 valid_range_p(
VALUE v,
int a,
int b)
144 return !(vi < a || vi > b);
152 l = date__strptime_internal(&str[si], slen - si, \ 153 fmt, sizeof fmt - 1, hash); \ 162 date__strptime_internal(
const char *str,
size_t slen,
163 const char *fmt,
size_t flen,
VALUE hash)
181 if (fmt[fi + 1] &&
strchr(
"cCxXyY", fmt[fi + 1]))
186 if (fmt[fi + 1] &&
strchr(
"deHImMSuUVwWy", fmt[fi + 1]))
195 if (strncmp(extz_pats[i], &fmt[fi],
196 strlen(extz_pats[i])) == 0) {
209 size_t l =
strlen(day_names[i]);
225 size_t l =
strlen(month_names[i]);
226 if (
strncasecmp(month_names[i], &str[si], l) == 0) {
260 if (str[si] ==
' ') {
266 if (!valid_range_p(n, 1, 31))
293 if (!valid_range_p(n, 0, 99))
307 if (str[si] ==
' ') {
313 if (!valid_range_p(n, 0, 24))
324 if (str[si] ==
' ') {
330 if (!valid_range_p(n, 1, 12))
341 if (!valid_range_p(n, 1, 366))
378 if (!valid_range_p(n, 0, 59))
389 if (!valid_range_p(n, 1, 12))
405 for (i = 0; i < 4; i++) {
406 size_t l =
strlen(merid_names[i]);
407 if (
strncasecmp(merid_names[i], &str[si], l) == 0) {
421 if (str[si] ==
'-') {
440 recur(
"%I:%M:%S %p");
448 if (!valid_range_p(n, 0, 60))
459 if (str[si] ==
'-') {
480 if (!valid_range_p(n, 0, 53))
482 set_hash(c ==
'U' ?
"wnum0" :
"wnum1", n);
491 if (!valid_range_p(n, 1, 7))
502 if (!valid_range_p(n, 1, 53))
517 if (!valid_range_p(n, 0, 6))
557 if (!valid_range_p(n, 0, 99))
571 static const char pat_source[] =
573 "(?:gmt|utc?)?[-+]\\d+(?:[,.:]\\d+(?::\\d+)?)?" 574 "|(?-i:[[:alpha:].\\s]+)(?:standard|daylight)\\s+time\\b" 575 "|(?-i:[[:alpha:]]+)(?:\\s+dst)?\\b" 581 pat =
rb_reg_new(pat_source,
sizeof pat_source - 1,
613 recur(
"%a %b %e %H:%M:%S %Z %Y");
621 if (str[si] != fmt[fi])
632 while (isspace((
unsigned char)str[si]))
638 if (str[si] != fmt[fi])
654 const char *fmt,
size_t flen,
VALUE hash)
659 si = date__strptime_internal(str, slen, fmt, flen, hash);
#define rb_rational_new2(x, y)
size_t strlen(const char *)
void rb_backref_set(VALUE)
#define rb_usascii_str_new2
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
VALUE rb_backref_get(void)
VALUE date__strptime(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
#define ONIG_OPTION_IGNORECASE
#define READ_DIGITS(n, w)
#define ALLOCV_N(type, v, n)
void rb_gc_register_mark_object(VALUE obj)
VALUE rb_reg_new(const char *, long, int)
#define READ_DIGITS_MAX(n)
char * strchr(char *, char)
void rb_match_busy(VALUE)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
VALUE rb_usascii_str_new(const char *, long)
VALUE date_zone_to_diff(VALUE)
VALUE rb_reg_nth_match(int, VALUE)