[前][次][番号順一覧][スレッド一覧]

ruby-changes:55267

From: nobu <ko1@a...>
Date: Tue, 9 Apr 2019 10:27:41 +0900 (JST)
Subject: [ruby-changes:55267] nobu:r67474 (trunk): date: support for Reiwa, new Japanese era

nobu	2019-04-09 10:27:36 +0900 (Tue, 09 Apr 2019)

  New Revision: 67474

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67474

  Log:
    date: support for Reiwa, new Japanese era
    
    [Feature #15742]

  Modified files:
    trunk/NEWS
    trunk/ext/date/date_core.c
    trunk/ext/date/date_parse.c
    trunk/test/date/test_date_parse.rb
    trunk/test/date/test_date_strftime.rb
Index: test/date/test_date_strftime.rb
===================================================================
--- test/date/test_date_strftime.rb	(revision 67473)
+++ test/date/test_date_strftime.rb	(revision 67474)
@@ -407,6 +407,7 @@ class TestDateStrftime < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/date/test_date_strftime.rb#L407
     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::Tes https://github.com/ruby/ruby/blob/trunk/test/date/test_date_strftime.rb#L418
        H01.01.08
        H18.09.01
        H31.04.30
+       R01.05.01
     ).each do |s|
       assert_equal(s, Date.parse(s).jisx0301)
     end
Index: test/date/test_date_parse.rb
===================================================================
--- test/date/test_date_parse.rb	(revision 67473)
+++ test/date/test_date_parse.rb	(revision 67474)
@@ -999,6 +999,9 @@ class TestDateParse < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L999
     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::TestCa https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1042
     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::TestCa https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1148
     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::TestCa https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1163
     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
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 67473)
+++ ext/date/date_core.c	(revision 67474)
@@ -7039,10 +7039,14 @@ jisx0301_date_format(char *fmt, size_t s https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L7039
 	    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;
     }
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 67473)
+++ ext/date/date_parse.c	(revision 67474)
@@ -1212,7 +1212,7 @@ parse_iso2(VALUE str, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L1212
     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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L1225
       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;
Index: NEWS
===================================================================
--- NEWS	(revision 67473)
+++ NEWS	(revision 67474)
@@ -62,6 +62,12 @@ CSV:: https://github.com/ruby/ruby/blob/trunk/NEWS#L62
   * 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.

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]