]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
set hook to add ordinal for Chinese(cn && tw) with modifing the tests 750/head
authorjiyinyiyong <jiyinyiyong@gmail.com>
Sat, 27 Apr 2013 03:44:44 +0000 (11:44 +0800)
committerjiyinyiyong <jiyinyiyong@gmail.com>
Sat, 27 Apr 2013 03:44:44 +0000 (11:44 +0800)
lang/zh-cn.js
lang/zh-tw.js
moment.js
test/lang/zh-cn.js
test/lang/zh-tw.js

index 7d3447b3a2145463fcf613a8a81972fc5967c8c1..e755416df9e05d03f7ef640909f47b7683164cb6 100644 (file)
@@ -40,6 +40,21 @@ require('../moment').lang('zh-cn', {
         lastWeek : '[上]ddddLT',
         sameElse : 'L'
     },
+    ordinal : function (number, period) {
+        switch (period) {
+        case "d" :
+        case "D" :
+        case "DDD" :
+            return number + "日";
+        case "M" :
+            return number + "月";
+        case "w" :
+        case "W" :
+            return number + "周";
+        default :
+            return number;
+        }
+    },
     relativeTime : {
         future : "%s内",
         past : "%s前",
index 30dbefc008e6f20361ef59bb95c70a9f2dece644..ee9b87b53930309afb7e1c92474d71fc25445989 100644 (file)
@@ -40,6 +40,21 @@ require('../moment').lang('zh-tw', {
         lastWeek : '[上]ddddLT',
         sameElse : 'L'
     },
+    ordinal : function (number, period) {
+        switch (period) {
+        case "d" :
+        case "D" :
+        case "DDD" :
+            return number + "日";
+        case "M" :
+            return number + "月";
+        case "w" :
+        case "W" :
+            return number + "週";
+        default :
+            return number;
+        }
+    },
     relativeTime : {
         future : "%s內",
         past : "%s前",
index 0ebc5f5e9bbeee9b6df18b63452221cd485edc5b..51930ec923882142fabe1f5f97cd08dba1a6320d 100644 (file)
--- a/moment.js
+++ b/moment.js
             return leftZeroFill(func.call(this, a), count);
         };
     }
-    function ordinalizeToken(func) {
+    function ordinalizeToken(func, period) {
         return function (a) {
-            return this.lang().ordinal(func.call(this, a));
+            return this.lang().ordinal(func.call(this, a), period);
         };
     }
 
     while (ordinalizeTokens.length) {
         i = ordinalizeTokens.pop();
-        formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i]);
+        formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
     }
     while (paddedTokens.length) {
         i = paddedTokens.pop();
index 4a72e19bd7c5d400e0ff0c17be9bda3c2cbd3e3a..7e2d4b79a63d113defdca4123c1bb8059f6ae0ba 100644 (file)
@@ -44,20 +44,20 @@ exports["lang:zh-cn"] = {
         test.expect(22);
 
         var a = [
-                ['dddd, MMMM Do YYYY, a h:mm:ss',      '星期日, 二月 14 2010, 下午 3:25:50'],
+                ['dddd, MMMM Do YYYY, a h:mm:ss',      '星期日, 二月 14 2010, 下午 3:25:50'],
                 ['ddd, Ah',                            '周日, 下午3'],
-                ['M Mo MM MMMM MMM',                   '2 2 02 二月 2月'],
+                ['M Mo MM MMMM MMM',                   '2 2 02 二月 2月'],
                 ['YYYY YY',                            '2010 10'],
-                ['D Do DD',                            '14 14 14'],
-                ['d do dddd ddd dd',                   '0 0 星期日 周日 日'],
-                ['DDD DDDo DDDD',                      '45 45 045'],
-                ['w wo ww',                            '8 8 08'],
+                ['D Do DD',                            '14 14 14'],
+                ['d do dddd ddd dd',                   '0 0 星期日 周日 日'],
+                ['DDD DDDo DDDD',                      '45 45 045'],
+                ['w wo ww',                            '8 8 08'],
                 ['h hh',                               '3 03'],
                 ['H HH',                               '15 15'],
                 ['m mm',                               '25 25'],
                 ['s ss',                               '50 50'],
                 ['a A',                                '下午 下午'],
-                ['[the] DDDo [day of the year]',       'the 45 day of the year'],
+                ['[这年的第] DDDo',                     '这年的第 45日'],
                 ['L',                                  '2010年2月14日'],
                 ['LL',                                 '2010年2月14日'],
                 ['LLL',                                '2010年2月14日下午3点25'],
@@ -345,11 +345,11 @@ exports["lang:zh-cn"] = {
     "weeks year starting sunday format" : function(test) {
         test.expect(5);
 
-        test.equal(moment([2012, 0,  1]).format('w ww wo'), '1 01 1', "Jan  1 2012 should be week 1");
-        test.equal(moment([2012, 0,  7]).format('w ww wo'), '1 01 1', "Jan  7 2012 should be week 1");
-        test.equal(moment([2012, 0,  8]).format('w ww wo'), '2 02 2', "Jan  8 2012 should be week 2");
-        test.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', "Jan 14 2012 should be week 2");
-        test.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', "Jan 15 2012 should be week 3");
+        test.equal(moment([2012, 0,  1]).format('w ww wo'), '1 01 1周', "Jan  1 2012 应该是第 1周");
+        test.equal(moment([2012, 0,  7]).format('w ww wo'), '1 01 1周', "Jan  7 2012 应该是第 1周");
+        test.equal(moment([2012, 0,  8]).format('w ww wo'), '2 02 2周', "Jan  8 2012 应该是第 2周");
+        test.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2周', "Jan 14 2012 应该是第 2周");
+        test.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3周', "Jan 15 2012 应该是第 3周");
 
         test.done();
     }
index 3c26815d844265857cb3e0fcecbc68cb788e0bc1..8990c5de99a4b5fb5a50328b0865576b01825014 100644 (file)
@@ -42,20 +42,20 @@ exports["lang:zh-tw"] = {
         test.expect(22);
 
         var a = [
-                ['dddd, MMMM Do YYYY, a h:mm:ss',      '星期日, 二月 14 2010, 下午 3:25:50'],
+                ['dddd, MMMM Do YYYY, a h:mm:ss',      '星期日, 二月 14 2010, 下午 3:25:50'],
                 ['ddd, Ah',                            '週日, 下午3'],
-                ['M Mo MM MMMM MMM',                   '2 2 02 二月 2月'],
+                ['M Mo MM MMMM MMM',                   '2 2 02 二月 2月'],
                 ['YYYY YY',                            '2010 10'],
-                ['D Do DD',                            '14 14 14'],
-                ['d do dddd ddd dd',                   '0 0 星期日 週日 日'],
-                ['DDD DDDo DDDD',                      '45 45 045'],
-                ['w wo ww',                            '8 8 08'],
+                ['D Do DD',                            '14 14 14'],
+                ['d do dddd ddd dd',                   '0 0 星期日 週日 日'],
+                ['DDD DDDo DDDD',                      '45 45 045'],
+                ['w wo ww',                            '8 8 08'],
                 ['h hh',                               '3 03'],
                 ['H HH',                               '15 15'],
                 ['m mm',                               '25 25'],
                 ['s ss',                               '50 50'],
                 ['a A',                                '下午 下午'],
-                ['[the] DDDo [day of the year]',       'the 45 day of the year'],
+                ['[這年的第] DDDo',                     '這年的第 45日'],
                 ['L',                                  '2010年2月14日'],
                 ['LL',                                 '2010年2月14日'],
                 ['LLL',                                '2010年2月14日下午3點25'],
@@ -347,11 +347,11 @@ exports["lang:zh-tw"] = {
     "weeks year starting sunday format" : function(test) {
         test.expect(5);
 
-        test.equal(moment([2012, 0,  1]).format('w ww wo'), '1 01 1', "Jan  1 2012 should be week 1");
-        test.equal(moment([2012, 0,  7]).format('w ww wo'), '1 01 1', "Jan  7 2012 should be week 1");
-        test.equal(moment([2012, 0,  8]).format('w ww wo'), '2 02 2', "Jan  8 2012 should be week 2");
-        test.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', "Jan 14 2012 should be week 2");
-        test.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', "Jan 15 2012 should be week 3");
+        test.equal(moment([2012, 0,  1]).format('w ww wo'), '1 01 1週', "Jan  1 2012 應該是第 1週");
+        test.equal(moment([2012, 0,  7]).format('w ww wo'), '1 01 1週', "Jan  7 2012 應該是第 1週");
+        test.equal(moment([2012, 0,  8]).format('w ww wo'), '2 02 2週', "Jan  8 2012 應該是第 2週");
+        test.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2週', "Jan 14 2012 應該是第 2週");
+        test.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3週', "Jan 15 2012 應該是第 3週");
 
         test.done();
     }