]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[locale] Fix Japanese locale (#4413)
authorAtsushi Tanaka <bgpat@users.noreply.github.com>
Sun, 4 Mar 2018 07:26:02 +0000 (16:26 +0900)
committerKunal Marwaha <marwahaha@berkeley.edu>
Sun, 4 Mar 2018 07:26:02 +0000 (23:26 -0800)
* Fix calendar format for Japanese

* Fix format string for Japanese

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

index 3aea68a176837a721fa9de992eb885989356a798..9812a736319131ffbbf30efa68e05b878554d350 100644 (file)
@@ -16,11 +16,11 @@ export default moment.defineLocale('ja', {
         L : 'YYYY/MM/DD',
         LL : 'YYYY年M月D日',
         LLL : 'YYYY年M月D日 HH:mm',
-        LLLL : 'YYYY年M月D日 HH:mm dddd',
+        LLLL : 'YYYY年M月D日 dddd HH:mm',
         l : 'YYYY/MM/DD',
         ll : 'YYYY年M月D日',
         lll : 'YYYY年M月D日 HH:mm',
-        llll : 'YYYY年M月D日 HH:mm dddd'
+        llll : 'YYYY年M月D日(ddd) HH:mm'
     },
     meridiemParse: /午前|午後/i,
     isPM : function (input) {
@@ -36,9 +36,21 @@ export default moment.defineLocale('ja', {
     calendar : {
         sameDay : '[今日] LT',
         nextDay : '[明日] LT',
-        nextWeek : '[来週]dddd LT',
+        nextWeek : function (now) {
+            if (now.week() < this.week()) {
+                return '[来週]dddd LT';
+            } else {
+                return 'dddd LT';
+            }
+        },
         lastDay : '[昨日] LT',
-        lastWeek : '[前週]dddd LT',
+        lastWeek : function (now) {
+            if (this.week() < now.week()) {
+                return '[先週]dddd LT';
+            } else {
+                return 'dddd LT';
+            }
+        },
         sameElse : 'L'
     },
     dayOfMonthOrdinalParse : /\d{1,2}日/,
index f9d184a2abe1426a77735bcfb0ed37aa0458b0aa..10c897c3167684faabf376c7be10a90f4291f5cb 100644 (file)
@@ -40,11 +40,11 @@ test('format', function (assert) {
             ['L',                                  '2010/02/14'],
             ['LL',                                 '2010年2月14日'],
             ['LLL',                                '2010年2月14日 15:25'],
-            ['LLLL',                               '2010年2月14日 15:25 日曜日'],
+            ['LLLL',                               '2010年2月14日 日曜日 15:25'],
             ['l',                                  '2010/02/14'],
             ['ll',                                 '2010年2月14日'],
             ['lll',                                '2010年2月14日 15:25'],
-            ['llll',                               '2010年2月14日 15:25 日曜日']
+            ['llll',                               '2010年2月14日(日) 15:25']
         ],
         b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
         i;
@@ -126,25 +126,43 @@ test('calendar day', function (assert) {
 
 test('calendar next week', function (assert) {
     var i, m;
+    var dow = moment().day();
     for (i = 2; i < 7; i++) {
         m = moment().add({d: i});
-        assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days current time');
-        m.hours(0).minutes(0).seconds(0).milliseconds(0);
-        assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days beginning of day');
-        m.hours(23).minutes(59).seconds(59).milliseconds(999);
-        assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days end of day');
+        if (dow + i < 7) {
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today + ' + i + ' days current time');
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today + ' + i + ' days beginning of day');
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today + ' + i + ' days end of day');
+        } else {
+            assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days current time');
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days beginning of day');
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(m.calendar(),       m.format('[来週]dddd LT'),  'Today + ' + i + ' days end of day');
+        }
     }
 });
 
 test('calendar last week', function (assert) {
     var i, m;
+    var dow = moment().day();
     for (i = 2; i < 7; i++) {
         m = moment().subtract({d: i});
-        assert.equal(m.calendar(),       m.format('[前週]dddd LT'),  'Today - ' + i + ' days current time');
-        m.hours(0).minutes(0).seconds(0).milliseconds(0);
-        assert.equal(m.calendar(),       m.format('[前週]dddd LT'),  'Today - ' + i + ' days beginning of day');
-        m.hours(23).minutes(59).seconds(59).milliseconds(999);
-        assert.equal(m.calendar(),       m.format('[前週]dddd LT'),  'Today - ' + i + ' days end of day');
+        if (dow < i) {
+            assert.equal(m.calendar(),       m.format('[先週]dddd LT'),  'Today - ' + i + ' days current time');
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(m.calendar(),       m.format('[先週]dddd LT'),  'Today - ' + i + ' days beginning of day');
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(m.calendar(),       m.format('[先週]dddd LT'),  'Today - ' + i + ' days end of day');
+        } else {
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today - ' + i + ' days current time');
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today - ' + i + ' days beginning of day');
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(m.calendar(),       m.format('dddd LT'),  'Today - ' + i + ' days end of day');
+        }
     }
 });