ruby-changes:56573
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Jul 2019 09:41:53 +0900 (JST)
Subject: [ruby-changes:56573] Nobuyoshi Nakada: 75fb0a9afa (master): Allow mday in Date.iso8601 to be omitted
https://git.ruby-lang.org/ruby.git/commit/?id=75fb0a9afa From 75fb0a9afad1685cedee9c7665a7f30ec95068fc Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Jul 2019 09:30:58 +0900 Subject: Allow mday in Date.iso8601 to be omitted [Bug #12285] diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index e0634c3..ab46bda 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -2262,8 +2262,8 @@ iso8601_ext_datetime_cb(VALUE m, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L2262 s[i] = rb_reg_nth_match(i, m); } - if (!NIL_P(s[3])) { - set_hash("mday", str2num(s[3])); + if (!NIL_P(s[1])) { + if (!NIL_P(s[3])) set_hash("mday", str2num(s[3])); if (strcmp(RSTRING_PTR(s[1]), "-") != 0) { y = str2num(s[1]); if (RSTRING_LEN(s[1]) < 4) @@ -2320,7 +2320,7 @@ static int https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L2320 iso8601_ext_datetime(VALUE str, VALUE hash) { static const char pat_source[] = - "\\A\\s*(?:([-+]?\\d{2,}|-)-(\\d{2})?-(\\d{2})|" + "\\A\\s*(?:([-+]?\\d{2,}|-)-(\\d{2})?(?:-(\\d{2}))?|" "([-+]?\\d{2,})?-(\\d{3})|" "(\\d{4}|\\d{2})?-w(\\d{2})-(\\d)|" "-w-(\\d))" diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index e17fd3e..dda952b 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -712,6 +712,9 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L712 h = Date._iso8601('2001-02-03T04:05:06.07+01:00') assert_equal([2001, 2, 3, 4, 5, 6, 3600], h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02') + assert_equal([2001, 2], + h.values_at(:year, :mon)) h = Date._iso8601('010203T040506Z') assert_equal([2001, 2, 3, 4, 5, 6, 0], -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/