diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index fcc9e33..ccbab09 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -3073,7 +3073,8 @@ static int jisx0301(VALUE str, VALUE hash) { static const char pat_source[] = - "\\A\\s*([" JISX0301_ERA_INITIALS "])?(\\d{2})\\.(\\d{2})\\.(\\d{2})" + "\\A\\s*([" JISX0301_ERA_INITIALS "])?" + "(\\d{2}|(?<=[" JISX0301_ERA_INITIALS "])\\d{3,})\\.(\\d{2})\\.(\\d{2})" "(?:t" "(?:(\\d{2}):(\\d{2})(?::(\\d{2})(?:[,.](\\d*))?)?" "(z|[-+]\\d{2}(?::?\\d{2})?)?)?)?\\s*\\z"; diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index cfe0b66..89fb34e 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -1075,6 +1075,16 @@ def test__jisx0301 h = Date._jisx0301('R01.05.01') assert_equal([2019, 5, 1, nil, nil, nil, nil], h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R100.05.01') + assert_equal([2118, 5, 1, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R100.05.01T04:05:06+09:00') + assert_equal([2118, 5, 1, 4, 5, 6, 32400], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('100.05.01') + assert_equal({}, h) + d = Date.new(2118, 5, 1) + assert_equal(d, Date.jisx0301(d.jisx0301)) h = Date._jisx0301('H13.02.03T04:05:06') assert_equal([2001, 2, 3, 4, 5, 6, nil],