diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-09 01:27:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-09 01:27:36 +0000 |
commit | 320c98b436b5277678907b9ba32e4c6cdd3678a0 (patch) | |
tree | 9ede4685aca051866e93d82752675d9b956dfd39 | |
parent | 63e66f08b6b524aff2bce99e30ef4fb343b2fe30 (diff) |
date: support for Reiwa, new Japanese era
[Feature #15742]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | ext/date/date_core.c | 6 | ||||
-rw-r--r-- | ext/date/date_parse.c | 3 | ||||
-rw-r--r-- | test/date/test_date_parse.rb | 24 | ||||
-rw-r--r-- | test/date/test_date_strftime.rb | 2 |
5 files changed, 39 insertions, 2 deletions
@@ -62,6 +62,12 @@ CSV:: * Upgrade to 3.0.4. See https://github.com/ruby/csv/blob/master/NEWS.md. +Date:: + + * Date.jisx0301, Date#jisx0301, and Date.parse provisionally support the + new Japanese era as an informal extension, until the new JIS X 0301 is + issued. [Feature #15742] + ERB:: * Prohibit marshaling ERB instance. diff --git a/ext/date/date_core.c b/ext/date/date_core.c index b6f806ff1f..67ed6171a7 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -7039,10 +7039,14 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y) c = 'S'; s = 1925; } - else { + else if (d < 2458605) { c = 'H'; s = 1988; } + else { + c = 'R'; + s = 2018; + } snprintf(fmt, size, "%c%02ld" ".%%m.%%d", c, FIX2INT(y) - s); return fmt; } diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 5bd10fb061..e0634c39f1 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -1212,7 +1212,7 @@ parse_iso2(VALUE str, VALUE hash) return 1; } -#define JISX0301_ERA_INITIALS "mtsh" +#define JISX0301_ERA_INITIALS "mtshr" #define JISX0301_DEFAULT_ERA 'H' /* obsolete */ static int @@ -1225,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; diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index 7907295bf4..e17fd3eb25 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -999,6 +999,9 @@ class TestDateParse < Test::Unit::TestCase h = Date._jisx0301('H31.05.01') assert_equal([2019, 5, 1, nil, nil, nil, nil], h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + 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('H13.02.03T04:05:06') assert_equal([2001, 2, 3, 4, 5, 6, nil], @@ -1039,6 +1042,19 @@ class TestDateParse < Test::Unit::TestCase assert_equal([2019, 5, 1, 4, 5, 6, 3600], h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R01.05.01T04:05:06') + assert_equal([2019, 5, 1, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R01.05.01T04:05:06,07') + assert_equal([2019, 5, 1, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R01.05.01T04:05:06Z') + assert_equal([2019, 5, 1, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('R01.05.01T04:05:06.07+0100') + assert_equal([2019, 5, 1, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('') assert_equal({}, h) end @@ -1132,6 +1148,10 @@ class TestDateParse < Test::Unit::TestCase assert_equal(Date.new(2019,5,1), d) assert_equal(Date::ITALY + 10, d.start) + d = Date.jisx0301('R01.05.01', Date::ITALY + 10) + assert_equal(Date.new(2019,5,1), d) + assert_equal(Date::ITALY + 10, d.start) + d = DateTime.jisx0301('H13.02.03T04:05:06+07:00', Date::ITALY + 10) assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) assert_equal(Date::ITALY + 10, d.start) @@ -1143,6 +1163,10 @@ class TestDateParse < Test::Unit::TestCase d = DateTime.jisx0301('H31.05.01T04:05:06+07:00', Date::ITALY + 10) assert_equal(DateTime.new(2019,5,1,4,5,6,'+07:00'), d) assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.jisx0301('R01.05.01T04:05:06+07:00', Date::ITALY + 10) + assert_equal(DateTime.new(2019,5,1,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) end def test_given_string diff --git a/test/date/test_date_strftime.rb b/test/date/test_date_strftime.rb index e52d4de1ae..dc237a909d 100644 --- a/test/date/test_date_strftime.rb +++ b/test/date/test_date_strftime.rb @@ -407,6 +407,7 @@ class TestDateStrftime < Test::Unit::TestCase assert_equal('H01.01.08', Date.parse('1989-01-08').jisx0301) assert_equal('H18.09.01', Date.parse('2006-09-01').jisx0301) assert_equal('H31.04.30', Date.parse('2019-04-30').jisx0301) + assert_equal('R01.05.01', Date.parse('2019-05-01').jisx0301) %w(M06.01.01 M45.07.29 @@ -417,6 +418,7 @@ class TestDateStrftime < Test::Unit::TestCase H01.01.08 H18.09.01 H31.04.30 + R01.05.01 ).each do |s| assert_equal(s, Date.parse(s).jisx0301) end |