From: Tim Wood Date: Fri, 23 Mar 2012 18:43:04 +0000 (-0700) Subject: remove am/AM/pm/PM from meridiem X-Git-Tag: 1.5.1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b34ba9429ab638563c8260f5293f3ef5f22192ae;p=thirdparty%2Fmoment.git remove am/AM/pm/PM from meridiem Changing to a function. #222 #228 --- diff --git a/lang/ca.js b/lang/ca.js index 42e2f1332..e97110639 100644 --- a/lang/ca.js +++ b/lang/ca.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : function () { return '[avui a ' + ((this.hours() !== 1) ? 'les' : 'la') + '] LT'; diff --git a/lang/da.js b/lang/da.js index c6a76b466..1fef05168 100644 --- a/lang/da.js +++ b/lang/da.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY h:mm A", LLLL : "dddd D. MMMM, YYYY h:mm A" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : '[I dag kl.] LT', nextDay : '[I morgen kl.] LT', diff --git a/lang/de.js b/lang/de.js index b1742c181..2461d9630 100644 --- a/lang/de.js +++ b/lang/de.js @@ -11,12 +11,6 @@ LLL : "D. MMMM YYYY LT", LLLL : "dddd, D. MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: "[Heute um] LT", sameElse: "L", diff --git a/lang/en-gb.js b/lang/en-gb.js index 2a2be53d5..1554ba0e8 100644 --- a/lang/en-gb.js +++ b/lang/en-gb.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd, D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : '[Today at] LT', nextDay : '[Tomorrow at] LT', diff --git a/lang/es.js b/lang/es.js index 6da12ad71..0a5df707a 100644 --- a/lang/es.js +++ b/lang/es.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : function () { return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT'; diff --git a/lang/eu.js b/lang/eu.js index ff3a8c4e3..ee52287a2 100644 --- a/lang/eu.js +++ b/lang/eu.js @@ -11,12 +11,6 @@ LLL : "YYYYko MMMMren D[a] LT", LLLL : "dddd, YYYYko MMMMren D[a] LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : '[gaur] LT[etan]', nextDay : '[bihar] LT[etan]', diff --git a/lang/fi.js b/lang/fi.js index fff2d16a9..3a4ef042a 100644 --- a/lang/fi.js +++ b/lang/fi.js @@ -55,12 +55,6 @@ LLL : "Do MMMMt\\a YYYY, klo LT", LLLL : "dddd, Do MMMMt\\a YYYY, klo LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : '[tänään] [klo] LT', nextDay : '[huomenna] [klo] LT', diff --git a/lang/fr.js b/lang/fr.js index c9b08ed2b..932dbc440 100644 --- a/lang/fr.js +++ b/lang/fr.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: "[Aujourd'hui à] LT", nextDay: '[Demain à] LT', diff --git a/lang/gl.js b/lang/gl.js index ccde1d382..54ffd2e62 100644 --- a/lang/gl.js +++ b/lang/gl.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : function () { return '[hoxe ' + ((this.hours() !== 1) ? 'ás' : 'a') + '] LT'; diff --git a/lang/it.js b/lang/it.js index 9f4843069..094a259c1 100644 --- a/lang/it.js +++ b/lang/it.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd, D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[Oggi alle] LT', nextDay: '[Domani alle] LT', diff --git a/lang/kr.js b/lang/kr.js index 39b68421c..6f4146c69 100644 --- a/lang/kr.js +++ b/lang/kr.js @@ -11,12 +11,9 @@ LLL : "YYYY년 MMMM D일 LT", LLLL : "YYYY년 MMMM D일 dddd LT" }, - meridiem : { - AM : '오전', - am : '오전', - PM : '오후', - pm : '오후' - }, + meridiem : function(hour, minute, isUpper) { + return hour < 12 ? '오전' : '오후'; + }, calendar : { sameDay : '오늘 LT', nextDay : '내일 LT', diff --git a/lang/nb.js b/lang/nb.js index 96940e645..d5a7f1d67 100644 --- a/lang/nb.js +++ b/lang/nb.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[I dag klokken] LT', nextDay: '[I morgen klokken] LT', diff --git a/lang/nl.js b/lang/nl.js index fda822745..a52b3d2c6 100644 --- a/lang/nl.js +++ b/lang/nl.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[Vandaag om] LT', nextDay: '[Morgen om] LT', diff --git a/lang/pl.js b/lang/pl.js index 324c8b55c..a81a3e2b2 100644 --- a/lang/pl.js +++ b/lang/pl.js @@ -33,12 +33,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd, D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[Dziś o] LT', nextDay: '[Jutro o] LT', diff --git a/lang/pt.js b/lang/pt.js index 42fc9f1dd..7410dc953 100644 --- a/lang/pt.js +++ b/lang/pt.js @@ -11,12 +11,6 @@ LLL : "D \\de MMMM \\de YYYY LT", LLLL : "dddd, D \\de MMMM \\de YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[Hoje às] LT', nextDay: '[Amanhã às] LT', diff --git a/lang/sv.js b/lang/sv.js index 6a0059862..bde95daa6 100644 --- a/lang/sv.js +++ b/lang/sv.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay: '[Idag klockan] LT', nextDay: '[Imorgon klockan] LT', diff --git a/lang/tr.js b/lang/tr.js index 4295b6670..b20765bd1 100644 --- a/lang/tr.js +++ b/lang/tr.js @@ -11,12 +11,6 @@ LLL : "D MMMM YYYY LT", LLLL : "dddd, D MMMM YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, calendar : { sameDay : '[bugün saat] LT', nextDay : '[yarın saat] LT', diff --git a/lang/zh-cn.js b/lang/zh-cn.js index 2a33484d6..fb76e09a8 100644 --- a/lang/zh-cn.js +++ b/lang/zh-cn.js @@ -11,11 +11,18 @@ LLL : "YYYY年MMMMD日LT", LLLL : "YYYY年MMMMD日ddddLT" }, - meridiem : { - AM : '上午', - am : '上午', - PM : '下午', - pm : '下午' + meridiem : function (hour, minute, isLower) { + if (hour < 9) { + return "早上"; + } else if (hour < 11 && minute < 30) { + return "上午"; + } else if (hour < 13 && minute < 30) { + return "中午"; + } else if (hour < 18) { + return "下午"; + } else { + return "晚上"; + } }, calendar : { sameDay : '[今天]LT', diff --git a/lang/zh-tw.js b/lang/zh-tw.js index b452a1654..45d4501fe 100644 --- a/lang/zh-tw.js +++ b/lang/zh-tw.js @@ -11,11 +11,18 @@ LLL : "YYYY年MMMMD日LT", LLLL : "YYYY年MMMMD日ddddLT" }, - meridiem : { - AM : '上午', - am : '上午', - PM : '下午', - pm : '下午' + meridiem : function (hour, minute, isLower) { + if (hour < 9) { + return "早上"; + } else if (hour < 11 && minute < 30) { + return "上午"; + } else if (hour < 13 && minute < 30) { + return "中午"; + } else if (hour < 18) { + return "下午"; + } else { + return "晚上"; + } }, calendar : { sameDay : '[今天]LT', diff --git a/moment.js b/moment.js index 693f5bc7b..3f0d671c9 100644 --- a/moment.js +++ b/moment.js @@ -165,9 +165,9 @@ return currentYear; // AM / PM case 'a' : - return currentHours > 11 ? meridiem.pm : meridiem.am; + return meridiem ? meridiem(currentHours, currentMinutes, false) : (currentHours > 11 ? 'pm' : 'am'); case 'A' : - return currentHours > 11 ? meridiem.PM : meridiem.AM; + return meridiem ? meridiem(currentHours, currentMinutes, true) : (currentHours > 11 ? 'PM' : 'AM'); // 24 HOUR case 'H' : return currentHours; @@ -501,7 +501,7 @@ if (languages[key]) { for (i = 0; i < paramsToParse.length; i++) { param = paramsToParse[i]; - moment[param] = languages[key][param] || moment[param]; + moment[param] = languages[key][param] || languages.en[param]; } } else { if (hasModule) { @@ -524,12 +524,7 @@ LLL : "MMMM D YYYY LT", LLLL : "dddd, MMMM D YYYY LT" }, - meridiem : { - AM : 'AM', - am : 'am', - PM : 'PM', - pm : 'pm' - }, + meridiem : false, calendar : { sameDay : '[Today at] LT', nextDay : '[Tomorrow at] LT', diff --git a/test/lang/zh-cn.js b/test/lang/zh-cn.js index c2dcf10df..311163f7b 100644 --- a/test/lang/zh-cn.js +++ b/test/lang/zh-cn.js @@ -147,12 +147,12 @@ exports["lang:zh-cn"] = { var a = moment().hours(2).minutes(0).seconds(0); - test.equal(moment(a).calendar(), "今天上午2点00", "today at the same time"); - test.equal(moment(a).add({ m: 25 }).calendar(), "今天上午2点25", "Now plus 25 min"); - test.equal(moment(a).add({ h: 1 }).calendar(), "今天上午3点00", "Now plus 1 hour"); - test.equal(moment(a).add({ d: 1 }).calendar(), "明天上午2点00", "tomorrow at the same time"); - test.equal(moment(a).subtract({ h: 1 }).calendar(), "今天上午1点00", "Now minus 1 hour"); - test.equal(moment(a).subtract({ d: 1 }).calendar(), "昨天上午2点00", "yesterday at the same time"); + test.equal(moment(a).calendar(), "今天早上2点00", "today at the same time"); + test.equal(moment(a).add({ m: 25 }).calendar(), "今天早上2点25", "Now plus 25 min"); + test.equal(moment(a).add({ h: 1 }).calendar(), "今天早上3点00", "Now plus 1 hour"); + test.equal(moment(a).add({ d: 1 }).calendar(), "明天早上2点00", "tomorrow at the same time"); + test.equal(moment(a).subtract({ h: 1 }).calendar(), "今天早上1点00", "Now minus 1 hour"); + test.equal(moment(a).subtract({ d: 1 }).calendar(), "昨天早上2点00", "yesterday at the same time"); test.done(); }, @@ -203,6 +203,25 @@ exports["lang:zh-cn"] = { test.equal(weeksAgo.calendar(), weeksAgo.format('L'), "2 weeks ago"); test.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), "in 2 weeks"); - test.done(); + test.done(); + }, + + "meridiem" : function(test) { + test.expect(10); + moment.lang('zh-cn'); + + test.equal(moment([2011, 2, 23, 0, 0]).format('a'), "早上", "morning"); + test.equal(moment([2011, 2, 23, 9, 0]).format('a'), "上午", "before noon"); + test.equal(moment([2011, 2, 23, 12, 0]).format('a'), "中午", "noon"); + test.equal(moment([2011, 2, 23, 13, 0]).format('a'), "下午", "after noon"); + test.equal(moment([2011, 2, 23, 18, 0]).format('a'), "晚上", "night"); + + test.equal(moment([2011, 2, 23, 0, 0]).format('A'), "早上", "morning"); + test.equal(moment([2011, 2, 23, 9, 0]).format('A'), "上午", "before noon"); + test.equal(moment([2011, 2, 23, 12, 0]).format('A'), "中午", "noon"); + test.equal(moment([2011, 2, 23, 13, 0]).format('A'), "下午", "afternoon"); + test.equal(moment([2011, 2, 23, 18, 0]).format('A'), "晚上", "night"); + + test.done(); } }; diff --git a/test/lang/zh-tw.js b/test/lang/zh-tw.js index bb519d098..c4e550d7e 100644 --- a/test/lang/zh-tw.js +++ b/test/lang/zh-tw.js @@ -147,12 +147,12 @@ exports["lang:zh-tw"] = { var a = moment().hours(2).minutes(0).seconds(0); - test.equal(moment(a).calendar(), "今天上午2點00", "today at the same time"); - test.equal(moment(a).add({ m: 25 }).calendar(), "今天上午2點25", "Now plus 25 min"); - test.equal(moment(a).add({ h: 1 }).calendar(), "今天上午3點00", "Now plus 1 hour"); - test.equal(moment(a).add({ d: 1 }).calendar(), "明天上午2點00", "tomorrow at the same time"); - test.equal(moment(a).subtract({ h: 1 }).calendar(), "今天上午1點00", "Now minus 1 hour"); - test.equal(moment(a).subtract({ d: 1 }).calendar(), "昨天上午2點00", "yesterday at the same time"); + test.equal(moment(a).calendar(), "今天早上2點00", "today at the same time"); + test.equal(moment(a).add({ m: 25 }).calendar(), "今天早上2點25", "Now plus 25 min"); + test.equal(moment(a).add({ h: 1 }).calendar(), "今天早上3點00", "Now plus 1 hour"); + test.equal(moment(a).add({ d: 1 }).calendar(), "明天早上2點00", "tomorrow at the same time"); + test.equal(moment(a).subtract({ h: 1 }).calendar(), "今天早上1點00", "Now minus 1 hour"); + test.equal(moment(a).subtract({ d: 1 }).calendar(), "昨天早上2點00", "yesterday at the same time"); test.done(); }, @@ -203,6 +203,25 @@ exports["lang:zh-tw"] = { test.equal(weeksAgo.calendar(), weeksAgo.format('L'), "2 weeks ago"); test.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), "in 2 weeks"); - test.done(); + test.done(); + }, + + "meridiem" : function(test) { + test.expect(10); + moment.lang('zh-cn'); + + test.equal(moment([2011, 2, 23, 0, 0]).format('a'), "早上", "morning"); + test.equal(moment([2011, 2, 23, 9, 0]).format('a'), "上午", "before noon"); + test.equal(moment([2011, 2, 23, 12, 0]).format('a'), "中午", "noon"); + test.equal(moment([2011, 2, 23, 13, 0]).format('a'), "下午", "after noon"); + test.equal(moment([2011, 2, 23, 18, 0]).format('a'), "晚上", "night"); + + test.equal(moment([2011, 2, 23, 0, 0]).format('A'), "早上", "morning"); + test.equal(moment([2011, 2, 23, 9, 0]).format('A'), "上午", "before noon"); + test.equal(moment([2011, 2, 23, 12, 0]).format('A'), "中午", "noon"); + test.equal(moment([2011, 2, 23, 13, 0]).format('A'), "下午", "afternoon"); + test.equal(moment([2011, 2, 23, 18, 0]).format('A'), "晚上", "night"); + + test.done(); } };