From: jiyinyiyong Date: Sat, 27 Apr 2013 03:44:44 +0000 (+0800) Subject: set hook to add ordinal for Chinese(cn && tw) with modifing the tests X-Git-Tag: 2.1.0~32^2~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F750%2Fhead;p=thirdparty%2Fmoment.git set hook to add ordinal for Chinese(cn && tw) with modifing the tests --- diff --git a/lang/zh-cn.js b/lang/zh-cn.js index 7d3447b3a..e755416df 100644 --- a/lang/zh-cn.js +++ b/lang/zh-cn.js @@ -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前", diff --git a/lang/zh-tw.js b/lang/zh-tw.js index 30dbefc00..ee9b87b53 100644 --- a/lang/zh-tw.js +++ b/lang/zh-tw.js @@ -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前", diff --git a/moment.js b/moment.js index 0ebc5f5e9..51930ec92 100644 --- a/moment.js +++ b/moment.js @@ -209,15 +209,15 @@ 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(); diff --git a/test/lang/zh-cn.js b/test/lang/zh-cn.js index 4a72e19bd..7e2d4b79a 100644 --- a/test/lang/zh-cn.js +++ b/test/lang/zh-cn.js @@ -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(); } diff --git a/test/lang/zh-tw.js b/test/lang/zh-tw.js index 3c26815d8..8990c5de9 100644 --- a/test/lang/zh-tw.js +++ b/test/lang/zh-tw.js @@ -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(); }