1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2019-04-09 01:27:36 +00:00
parent 63e66f08b6
commit 320c98b436
5 changed files with 39 additions and 2 deletions

6
NEWS
View file

@ -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.

View file

@ -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;
}

View file

@ -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;

View file

@ -997,6 +997,9 @@ class TestDateParse < Test::Unit::TestCase
assert_equal([2019, 4, 30, nil, nil, nil, nil],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
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))
@ -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

View file

@ -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