10static const char *day_names[] = {
11 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
12 "Thursday",
"Friday",
"Saturday",
13 "Sun",
"Mon",
"Tue",
"Wed",
17static 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"
25static const char *merid_names[] = {
30static 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) == '+')
59num_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])
78read_digits(
const char *s,
VALUE *
n,
size_t width)
87 if (++l == width)
break;
93 if ((4 * l *
sizeof(
char)) <= (
sizeof(
long)*
CHAR_BIT)) {
98 while ((
size_t)(s - os) < l) {
119#define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k"")), v)
120#define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k"")))
121#define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k"")))
125 set_hash("_fail", Qtrue); \
129#define fail_p() (!NIL_P(ref_hash("_fail")))
131#define READ_DIGITS(n,w) \
134 l = read_digits(&str[si], &n, w); \
140#define READ_DIGITS_MAX(n) READ_DIGITS(n, LONG_MAX)
143valid_range_p(
VALUE v,
int a,
int b)
147 return !(vi < a || vi > b);
155 l = date__strptime_internal(&str[si], slen - si, \
156 fmt, sizeof fmt - 1, hash); \
165date__strptime_internal(
const char *
str,
size_t slen,
166 const char *
fmt,
size_t flen,
VALUE hash)
189 if (
fmt[fi + 1] &&
strchr(
"deHImMSuUVwWy",
fmt[fi + 1]))
212 size_t l =
strlen(day_names[
i]);
228 size_t l =
strlen(month_names[
i]);
251 recur(
"%a %b %e %H:%M:%S %Y");
263 if (
str[si] ==
' ') {
269 if (!valid_range_p(
n, 1, 31))
296 if (!valid_range_p(
n, 0, 99))
310 if (
str[si] ==
' ') {
316 if (!valid_range_p(
n, 0, 24))
327 if (
str[si] ==
' ') {
333 if (!valid_range_p(
n, 1, 12))
344 if (!valid_range_p(
n, 1, 366))
381 if (!valid_range_p(
n, 0, 59))
392 if (!valid_range_p(
n, 1, 12))
408 for (
i = 0;
i < 4;
i++) {
409 size_t l =
strlen(merid_names[
i]);
424 if (
str[si] ==
'-') {
441 recur(
"%I:%M:%S %p");
449 if (!valid_range_p(
n, 0, 60))
460 if (
str[si] ==
'-') {
481 if (!valid_range_p(
n, 0, 53))
483 set_hash(c ==
'U' ?
"wnum0" :
"wnum1",
n);
492 if (!valid_range_p(
n, 1, 7))
503 if (!valid_range_p(
n, 1, 53))
518 if (!valid_range_p(
n, 0, 6))
558 if (!valid_range_p(
n, 0, 99))
572 static const char pat_source[] =
574 "(?:gmt|utc?)?[-+]\\d+(?:[,.:]\\d+(?::\\d+)?)?"
575 "|(?-i:[[:alpha:].\\s]+)(?:standard|daylight)\\s+time\\b"
576 "|(?-i:[[:alpha:]]+)(?:\\s+dst)?\\b"
582 pat =
rb_reg_new(pat_source,
sizeof pat_source - 1,
614 recur(
"%a %b %e %H:%M:%S %Z %Y");
633 while (isspace((
unsigned char)
str[si]))
655 const char *
fmt,
size_t flen,
VALUE hash)
660 si = date__strptime_internal(
str, slen,
fmt, flen, hash);
VALUE date__strptime(const char *str, size_t slen, const char *fmt, size_t flen, VALUE hash)
#define READ_DIGITS(n, w)
VALUE date_zone_to_diff(VALUE)
#define READ_DIGITS_MAX(n)
char str[HTML_ESCAPE_MAX_LEN+1]
#define ONIG_OPTION_IGNORECASE