summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-13 15:14:02 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-13 15:14:02 +0000
commitd6387f706834957d48e61716bc8053ec8b6aa6c5 (patch)
tree788d459744449f124b2d525a2c99218b0ec3b3b5 /test
parentd8cac3300f383a7b06c3958b30d2a5f2ee383c12 (diff)
merge revision(s) 66745,67397,67398,67399,67400,67409,67410,67411,67412,67425,67426,67473,67474: [Backport #15742]
Bump version to date-2.0.0. I forgot to change it when Ruby 2.6.0 was released. date_parse.c: extract Japanese era initials * expand tabs. date_parse.c: removed 'r' which is not in JIS X 0301 yet Added tests for end of Heisei date: use del_hash to extract an element destructively * expand tabs. date_parse.c: renamed JAPANESE prefix as JISX0301 date_parse.c: name JISX0301_DEFAULT_ERA date: make zone a substring to copy encoding and taintedness * expand tabs. date_core.c: [DOC] Heisei will be assumed if no-era [ci skip] date: support for Reiwa, new Japanese era [Feature #15742] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/date/test_date_parse.rb93
-rw-r--r--test/date/test_date_strftime.rb7
2 files changed, 98 insertions, 2 deletions
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index ac0eb85ca7..e17fd3eb25 100644
--- a/test/date/test_date_parse.rb
+++ b/test/date/test_date_parse.rb
@@ -121,6 +121,8 @@ class TestDateParse < Test::Unit::TestCase
[['S40.05.23T23:55:21-09:00',false],[1965,5,23,23,55,21,'-09:00',-9*3600,nil], __LINE__],
[['H11.05.23 23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__],
[['H11.05.23T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__],
+ [['H31.04.30 23:55:21Z',false],[2019,4,30,23,55,21,'Z',0,nil], __LINE__],
+ [['H31.04.30T23:55:21Z',false],[2019,4,30,23,55,21,'Z',0,nil], __LINE__],
# ofx date
[['19990523235521',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__],
@@ -416,7 +418,14 @@ class TestDateParse < Test::Unit::TestCase
a[1] = -1
a[2] = h[:yday]
end
- assert_equal(y, a, format('<failed at line %d>', l))
+ l = format('<failed at line %d>', l)
+ assert_equal(y, a, l)
+ if y[6]
+ h = Date._parse(x[0].dup.taint, *x[1..-1])
+ assert_equal(y[6], h[:zone], l)
+ assert_equal(y[6].encoding, h[:zone].encoding, l)
+ assert_predicate(h[:zone], :tainted?, l)
+ end
end
end
@@ -984,6 +993,15 @@ class TestDateParse < Test::Unit::TestCase
h = Date._jisx0301('S63.02.03')
assert_equal([1988, 2, 3, nil, nil, nil, nil],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+ h = Date._jisx0301('H31.04.30')
+ 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))
h = Date._jisx0301('H13.02.03T04:05:06')
assert_equal([2001, 2, 3, 4, 5, 6, nil],
@@ -998,6 +1016,45 @@ class TestDateParse < Test::Unit::TestCase
assert_equal([2001, 2, 3, 4, 5, 6, 3600],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+ h = Date._jisx0301('H31.04.30T04:05:06')
+ assert_equal([2019, 4, 30, 4, 5, 6, nil],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+ h = Date._jisx0301('H31.04.30T04:05:06,07')
+ assert_equal([2019, 4, 30, 4, 5, 6, nil],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+ h = Date._jisx0301('H31.04.30T04:05:06Z')
+ assert_equal([2019, 4, 30, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+ h = Date._jisx0301('H31.04.30T04:05:06.07+0100')
+ assert_equal([2019, 4, 30, 4, 5, 6, 3600],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
+
+ h = Date._jisx0301('H31.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('H31.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('H31.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('H31.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('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
@@ -1083,9 +1140,33 @@ class TestDateParse < Test::Unit::TestCase
assert_equal(Date.new(2001,2,3), d)
assert_equal(Date::ITALY + 10, d.start)
+ d = Date.jisx0301('H31.04.30', Date::ITALY + 10)
+ assert_equal(Date.new(2019,4,30), d)
+ assert_equal(Date::ITALY + 10, d.start)
+
+ d = Date.jisx0301('H31.05.01', Date::ITALY + 10)
+ 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)
+
+ d = DateTime.jisx0301('H31.04.30T04:05:06+07:00', Date::ITALY + 10)
+ assert_equal(DateTime.new(2019,4,30,4,5,6,'+07:00'), d)
+ assert_equal(Date::ITALY + 10, d.start)
+
+ 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
@@ -1120,6 +1201,16 @@ class TestDateParse < Test::Unit::TestCase
s0 = s.dup
assert_not_equal({}, Date._jisx0301(s))
assert_equal(s0, s)
+
+ s = 'H31.04.30T04:05:06,07Z'
+ s0 = s.dup
+ assert_not_equal({}, Date._jisx0301(s))
+ assert_equal(s0, s)
+
+ s = 'H31.05.01T04:05:06,07Z'
+ s0 = s.dup
+ assert_not_equal({}, Date._jisx0301(s))
+ assert_equal(s0, s)
end
end
diff --git a/test/date/test_date_strftime.rb b/test/date/test_date_strftime.rb
index a33eaa340f..dc237a909d 100644
--- a/test/date/test_date_strftime.rb
+++ b/test/date/test_date_strftime.rb
@@ -406,6 +406,8 @@ class TestDateStrftime < Test::Unit::TestCase
assert_equal('S64.01.07', Date.parse('1989-01-07').jisx0301)
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
@@ -414,7 +416,10 @@ class TestDateStrftime < Test::Unit::TestCase
S01.12.25
S64.01.07
H01.01.08
- H18.09.01).each do |s|
+ H18.09.01
+ H31.04.30
+ R01.05.01
+ ).each do |s|
assert_equal(s, Date.parse(s).jisx0301)
end