]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[locale] ja: Add new 'Reiwa' Era (#5471)
authorTakuya Sawada <takuya@tuntunkun.com>
Wed, 29 Apr 2020 21:48:05 +0000 (06:48 +0900)
committerGitHub <noreply@github.com>
Wed, 29 Apr 2020 21:48:05 +0000 (00:48 +0300)
* [locale] ja: Add new 'Reiwa' Era

* Apply coding convention

src/locale/ja.js
src/test/locale/ja.js

index 612a36984254ff70c008b91eec1d27954a4eca21..227591055b33052a840c966726af6c5e09e32b36 100644 (file)
@@ -6,6 +6,13 @@ import moment from '../moment';
 
 export default moment.defineLocale('ja', {
     eras: [
+        {
+            since: '2019-05-01',
+            offset: 1,
+            name: '令和',
+            narrow: '㋿',
+            abbr: 'R',
+        },
         {
             since: '1989-01-08',
             offset: 1,
index b4481e303cbf02ee35f16ecd13b86061c5a75e10..d3041ae8fcda969ef7e1cf4b2e50b243ab62bb12 100644 (file)
@@ -81,42 +81,36 @@ test('format', function (assert) {
 
 test('parse era', function (assert) {
     // strict
-    assert.equal(
-        moment('平成30年', 'NNNNy年', true).isValid(),
-        true,
-        '平成30年'
-    );
-    assert.equal(moment('平成30年', 'NNNNy年', true).year(), 2018, '平成30年');
-    assert.equal(
-        moment('平成30年', 'NNNNyo', true).isValid(),
-        true,
-        '平成30年'
-    );
-    assert.equal(moment('平成30年', 'NNNNyo', true).year(), 2018, '平成30年');
+    assert.equal(moment('令和2年', 'NNNNy年', true).isValid(), true, '令和2年');
+    assert.equal(moment('令和2年', 'NNNNy年', true).year(), 2020, '令和2年');
+    assert.equal(moment('令和2年', 'NNNNyo', true).isValid(), true, '令和2年');
+    assert.equal(moment('令和2年', 'NNNNyo', true).year(), 2020, '令和2年');
 
-    assert.equal(moment('平成30年', 'Ny年', true).isValid(), false, '平成30年');
-    assert.equal(moment('平成30年', 'Ny年', false).isValid(), true, '平成30年');
-    assert.equal(moment('ã\8d»30å¹´', 'Nyå¹´', true).isValid(), false, 'ã\8d»30年');
-    assert.equal(moment('ã\8d»30å¹´', 'Nyå¹´', false).isValid(), true, 'ã\8d»30年');
-    assert.equal(moment('H30年', 'Ny年', false).isValid(), true, 'H30年');
+    assert.equal(moment('令和2年', 'Ny年', true).isValid(), false, '令和2年');
+    assert.equal(moment('令和2年', 'Ny年', false).isValid(), true, '令和2年');
+    assert.equal(moment('ã\8b¿2å¹´', 'Nyå¹´', true).isValid(), false, 'ã\8b¿2年');
+    assert.equal(moment('ã\8b¿2å¹´', 'Nyå¹´', false).isValid(), true, 'ã\8b¿2年');
+    assert.equal(moment('R2', 'Ny', false).isValid(), true, 'R2');
 
     // abbrv
-    assert.equal(moment('H30年', 'Ny年', true).isValid(), true, 'H30年');
-    assert.equal(moment('H30年', 'Ny年', true).year(), 2018, 'H30年');
-    assert.equal(moment('H30年', 'NNNNy年', true).isValid(), false, 'H30年');
-    assert.equal(moment('H30年', 'NNNNNy年', true).isValid(), false, 'H30年');
+    assert.equal(moment('R2', 'Ny', true).isValid(), true, 'R2');
+    assert.equal(moment('R2', 'Ny', true).year(), 2020, 'R2');
+    assert.equal(moment('R2', 'NNNNy', true).isValid(), false, 'R2');
+    assert.equal(moment('R2', 'NNNNNy', true).isValid(), false, 'R2');
 
     // narrow
-    assert.equal(moment('ã\8d»30å¹´', 'Nyå¹´', true).isValid(), false, 'ã\8d»30年');
-    assert.equal(moment('ã\8d»30å¹´', 'NNNNyå¹´', true).isValid(), false, 'ã\8d»30年');
-    assert.equal(moment('ã\8d»30å¹´', 'NNNNNyå¹´', true).isValid(), true, 'ã\8d»30年');
-    assert.equal(moment('ã\8d»30å¹´', 'NNNNNyå¹´', true).year(), 2018, 'ã\8d»30年');
+    assert.equal(moment('ã\8b¿2å¹´', 'Nyå¹´', true).isValid(), false, 'ã\8b¿2年');
+    assert.equal(moment('ã\8b¿2å¹´', 'NNNNyå¹´', true).isValid(), false, 'ã\8b¿2年');
+    assert.equal(moment('ã\8b¿2å¹´', 'NNNNNyå¹´', true).isValid(), true, 'ã\8b¿2年');
+    assert.equal(moment('ã\8b¿2å¹´', 'NNNNNyå¹´', true).year(), 2020, 'ã\8b¿2年');
 
     // ordinal year
-    assert.equal(moment('平成30年', 'NNNNyo', true).year(), 2018, '平成30年');
-    assert.equal(moment('平成元年', 'NNNNyo', true).year(), 1989, '平成元年');
+    assert.equal(moment('令和2年', 'NNNNyo', true).year(), 2020, '平成30年');
+    assert.equal(moment('令和元年', 'NNNNyo', true).year(), 2019, '平成元年');
 
     // old eras
+    assert.equal(moment('平成30年', 'NNNNyo', true).year(), 2018, '平成30年');
+    assert.equal(moment('平成元年', 'NNNNyo', true).year(), 1989, '平成元年');
     assert.equal(moment('昭和64年', 'NNNNyo', true).year(), 1989, '昭和64年');
     assert.equal(moment('昭和元年', 'NNNNyo', true).year(), 1926, '昭和元年');
     assert.equal(moment('大正元年', 'NNNNyo', true).year(), 1912, '大正元年');
@@ -125,6 +119,20 @@ test('parse era', function (assert) {
 
 test('format era', function (assert) {
     var a = [
+            /* First day of Reiwa Era */
+            ['+002019-05-01', 'N, NN, NNN', 'R, R, R'],
+            ['+002019-05-01', 'NNNN', '令和'],
+            ['+002019-05-01', 'NNNNN', '㋿'],
+            ['+002019-05-01', 'y yy yyy yyyy', '1 01 001 0001'],
+            ['+002019-05-01', 'yo', '元年'],
+
+            /* Last day of Heisei Era */
+            ['+002019-04-30', 'N, NN, NNN', 'H, H, H'],
+            ['+002019-04-30', 'NNNN', '平成'],
+            ['+002019-04-30', 'NNNNN', '㍻'],
+            ['+002019-04-30', 'y yy yyy yyyy', '31 31 031 0031'],
+            ['+002019-04-30', 'yo', '31年'],
+
             /* First day of Heisei Era */
             ['+001989-01-08', 'N, NN, NNN', 'H, H, H'],
             ['+001989-01-08', 'NNNN', '平成'],