]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[locale] zh-cn: Improve next/prev week (#5447)
authorUlion <ulion2002@gmail.com>
Wed, 20 May 2020 05:55:31 +0000 (13:55 +0800)
committerGitHub <noreply@github.com>
Wed, 20 May 2020 05:55:31 +0000 (22:55 -0700)
src/locale/zh-cn.js
src/test/locale/zh-cn.js

index c775295465f50b007316faacb335d877aff76afb..ca7dee99627bdc51ddeaff7f93d5b338a467eb11 100644 (file)
@@ -2,6 +2,7 @@
 //! locale : Chinese (China) [zh-cn]
 //! author : suupic : https://github.com/suupic
 //! author : Zeno Zeng : https://github.com/zenozeng
+//! author : uu109 : https://github.com/uu109
 
 import moment from '../moment';
 
@@ -60,9 +61,21 @@ export default moment.defineLocale('zh-cn', {
     calendar: {
         sameDay: '[今天]LT',
         nextDay: '[明天]LT',
-        nextWeek: '[下]ddddLT',
+        nextWeek: function (now) {
+            if (now.week() !== this.week()) {
+                return '[下]dddLT';
+            } else {
+                return '[本]dddLT';
+            }
+        },
         lastDay: '[昨天]LT',
-        lastWeek: '[上]ddddLT',
+        lastWeek: function (now) {
+            if (this.week() !== now.week()) {
+                return '[上]dddLT';
+            } else {
+                return '[本]dddLT';
+            }
+        },
         sameElse: 'L',
     },
     dayOfMonthOrdinalParse: /\d{1,2}(日|月|周)/,
index 2ba8fbd21aa6e4377803166de63220868b3bd5bf..5763c757748edb3283c054def30e48cb202b9974 100644 (file)
@@ -310,50 +310,94 @@ test('calendar day', function (assert) {
 });
 
 test('calendar next week', function (assert) {
-    var i, m;
+    var i,
+        m,
+        week = moment().week();
     for (i = 2; i < 7; i++) {
         m = moment().add({ d: i });
-        assert.equal(
-            m.calendar(),
-            m.format('[下]ddddLT'),
-            'Today + ' + i + ' days current time'
-        );
-        m.hours(0).minutes(0).seconds(0).milliseconds(0);
-        assert.equal(
-            m.calendar(),
-            m.format('[下]ddddLT'),
-            'Today + ' + i + ' days beginning of day'
-        );
-        m.hours(23).minutes(59).seconds(59).milliseconds(999);
-        assert.equal(
-            m.calendar(),
-            m.format('[下]ddddLT'),
-            'Today + ' + i + ' days end of day'
-        );
+        if (week === m.week()) {
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today + ' + i + ' days current time'
+            );
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today + ' + i + ' days beginning of day'
+            );
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today + ' + i + ' days end of day'
+            );
+        } else {
+            assert.equal(
+                m.calendar(),
+                m.format('[下]dddLT'),
+                'Today + ' + i + ' days current time'
+            );
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(
+                m.calendar(),
+                m.format('[下]dddLT'),
+                'Today + ' + i + ' days beginning of day'
+            );
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(
+                m.calendar(),
+                m.format('[下]dddLT'),
+                'Today + ' + i + ' days end of day'
+            );
+        }
     }
 });
 
 test('calendar last week', function (assert) {
-    var i, m;
+    var i,
+        m,
+        week = moment().week();
     for (i = 2; i < 7; i++) {
         m = moment().subtract({ d: i });
-        assert.equal(
-            m.calendar(),
-            m.format('[上]ddddLT'),
-            'Today - ' + i + ' days current time'
-        );
-        m.hours(0).minutes(0).seconds(0).milliseconds(0);
-        assert.equal(
-            m.calendar(),
-            m.format('[上]ddddLT'),
-            'Today - ' + i + ' days beginning of day'
-        );
-        m.hours(23).minutes(59).seconds(59).milliseconds(999);
-        assert.equal(
-            m.calendar(),
-            m.format('[上]ddddLT'),
-            'Today - ' + i + ' days end of day'
-        );
+        if (week !== m.week()) {
+            assert.equal(
+                m.calendar(),
+                m.format('[上]dddLT'),
+                'Today - ' + i + ' days current time'
+            );
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(
+                m.calendar(),
+                m.format('[上]dddLT'),
+                'Today - ' + i + ' days beginning of day'
+            );
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(
+                m.calendar(),
+                m.format('[上]dddLT'),
+                'Today - ' + i + ' days end of day'
+            );
+        } else {
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today - ' + i + ' days current time'
+            );
+            m.hours(0).minutes(0).seconds(0).milliseconds(0);
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today - ' + i + ' days beginning of day'
+            );
+            m.hours(23).minutes(59).seconds(59).milliseconds(999);
+            assert.equal(
+                m.calendar(),
+                m.format('[本]dddLT'),
+                'Today - ' + i + ' days end of day'
+            );
+        }
     }
 });