summaryrefslogtreecommitdiff
path: root/ext/date/date_parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/date/date_parse.c')
-rw-r--r--ext/date/date_parse.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 69ac37f0a3..e0634c39f1 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -1212,6 +1212,9 @@ parse_iso2(VALUE str, VALUE hash)
return 1;
}
+#define JISX0301_ERA_INITIALS "mtshr"
+#define JISX0301_DEFAULT_ERA 'H' /* obsolete */
+
static int
gengo(int c)
{
@@ -1222,6 +1225,7 @@ gengo(int c)
case 'T': case 't': e = 1911; break;
case 'S': case 's': e = 1925; break;
case 'H': case 'h': e = 1988; break;
+ case 'R': case 'r': e = 2018; break;
default: e = 0; break;
}
return e;
@@ -1252,11 +1256,11 @@ parse_jis(VALUE str, VALUE hash)
{
static const char pat_source[] =
#ifndef TIGHT_PARSER
- "\\b([mtsh])(\\d+)\\.(\\d+)\\.(\\d+)"
+ "\\b([" JISX0301_ERA_INITIALS "])(\\d+)\\.(\\d+)\\.(\\d+)"
#else
BOS
FPW_COM FPT_COM
- "([mtsh])(\\d+)\\.(\\d+)\\.(\\d+)"
+ "([" JISX0301_ERA_INITIALS "])(\\d+)\\.(\\d+)\\.(\\d+)"
TEE_FPT COM_FPW
EOS
#endif
@@ -1859,30 +1863,26 @@ parse_ddd_cb(VALUE m, VALUE hash)
set_hash("zone", s5);
if (*cs5 == '[') {
- VALUE vbuf = 0;
- char *buf = ALLOCV_N(char, vbuf, l5 + 1);
- char *s1, *s2, *s3;
+ const char *s1, *s2;
VALUE zone;
- memcpy(buf, cs5, l5);
- buf[l5 - 1] = '\0';
-
- s1 = buf + 1;
- s2 = strchr(buf, ':');
+ l5 -= 2;
+ s1 = cs5 + 1;
+ s2 = memchr(s1, ':', l5);
if (s2) {
- *s2 = '\0';
s2++;
+ zone = rb_str_subseq(s5, s2 - cs5, l5 - (s2 - s1));
+ s5 = rb_str_subseq(s5, 1, s2 - s1);
}
- if (s2)
- s3 = s2;
- else
- s3 = s1;
- zone = rb_str_new2(s3);
+ else {
+ zone = rb_str_subseq(s5, 1, l5);
+ if (isdigit((unsigned char)*s1))
+ s5 = rb_str_append(rb_str_new_cstr("+"), zone);
+ else
+ s5 = zone;
+ }
set_hash("zone", zone);
- if (isdigit((unsigned char)*s1))
- *--s1 = '+';
- set_hash("offset", date_zone_to_diff(rb_str_new2(s1)));
- ALLOCV_END(vbuf);
+ set_hash("offset", date_zone_to_diff(s5));
}
RB_GC_GUARD(s5);
}
@@ -2175,7 +2175,7 @@ date__parse(VALUE str, VALUE comp)
#endif
{
- if (RTEST(ref_hash("_bc"))) {
+ if (RTEST(del_hash("_bc"))) {
VALUE y;
y = ref_hash("cwyear");
@@ -2190,7 +2190,7 @@ date__parse(VALUE str, VALUE comp)
}
}
- if (RTEST(ref_hash("_comp"))) {
+ if (RTEST(del_hash("_comp"))) {
VALUE y;
y = ref_hash("cwyear");
@@ -2213,9 +2213,6 @@ date__parse(VALUE str, VALUE comp)
}
- del_hash("_bc");
- del_hash("_comp");
-
{
VALUE zone = ref_hash("zone");
if (!NIL_P(zone) && NIL_P(ref_hash("offset")))
@@ -2954,7 +2951,7 @@ jisx0301_cb(VALUE m, VALUE hash)
s[i] = rb_reg_nth_match(i, m);
}
- ep = gengo(NIL_P(s[1]) ? 'h' : *RSTRING_PTR(s[1]));
+ ep = gengo(NIL_P(s[1]) ? JISX0301_DEFAULT_ERA : *RSTRING_PTR(s[1]));
set_hash("year", f_add(str2num(s[2]), INT2FIX(ep)));
set_hash("mon", str2num(s[3]));
set_hash("mday", str2num(s[4]));
@@ -2979,7 +2976,7 @@ static int
jisx0301(VALUE str, VALUE hash)
{
static const char pat_source[] =
- "\\A\\s*([mtsh])?(\\d{2})\\.(\\d{2})\\.(\\d{2})"
+ "\\A\\s*([" JISX0301_ERA_INITIALS "])?(\\d{2})\\.(\\d{2})\\.(\\d{2})"
"(?:t"
"(?:(\\d{2}):(\\d{2})(?::(\\d{2})(?:[,.](\\d*))?)?"
"(z|[-+]\\d{2}(?::?\\d{2})?)?)?)?\\s*\\z";