Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed the meridiem value for Chinese. #222

Closed
wants to merge 2 commits into from

3 participants

Rocky Meza Tim Wood jimmyye
Rocky Meza

In Chinese, there are more values for the meridiem value than just AM and PM. There are values that mean morning, before noon, noon, afternoon, and night time. I had to modify moment.js to handle a callback or default to the previous behavior.

If you accept #221, I am pretty sure that you will have a merge conflict in the calendar day tests. Here is what those tests should look like:

// zh-cn.js
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");
// zh-tw.js
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");
Rocky Meza rockymeza Fixed the meridiem value for Chinese.
In Chinese, there are more values for the meridiem value than just AM
and PM.  There are values that mean morning, before noon, noon,
afternoon, and night time.  I had to modify moment.js to handle a
callback or default to the previous behavior.
17aaf58
Tim Wood
Owner

Hmm, if we're adding moment.meridiem.lower and moment.meridiem.upper, should we just deprecate moment.meridiem.am/AM/pm/PM and default to hard coded am/pm?

I dont think any other languages use moment.meridiem.am besides south-east asian languages.

Rocky Meza

Are you saying that in all of the other language files, am/AM/pm/PM are all the same?

Tim Wood
Owner

Yes, am/pm are the same for all languages but Korean and Chinese.

Meridiem was added for the Korean translation, and I didn't know if any future language would need different strings for upper and lower case, hence the semi-redundant am/AM, pm/PM.

Rocky Meza

Is it possible to unify the meridiem method into one method? There is no point in having two methods if the only languages that would even use it don't even have uppercase/lowercase.

We could delete meridiem am/AM/pm/PM in all other language files and define a meridiem function that accepts hour, minute, case in those few languages that are different. That would shrink the filesize of most of the language definitions a little bit.

Tim Wood
Owner

Yeah, that's probably even better.

Rocky Meza

This is the line that I am talking about in #222

Rocky Meza

I went ahead and did that, but you don't have to merge that part of the pull request in if you don't want to.

I had to change something in the way that languages are added to moment that perhaps changed some functionality. I don't know if it is documented or intentional, but there is the capability for a language definition to inherit from another language definition. Previously, the language definition would inherit from the last language defined. Now it inherits from English. I don't know if this functionality was intentional. When I removed all of the meridiem references it broke the tests with regard to the languages after Korean.

Since English is default and is always available I decided that language definition files could inherit from it instead of disabling inheritance altogether.

Rocky Meza

The tests pass if we take off inheritance or if we use the English as a fallback. However, I don't know about people's custom language definition files, if indeed there are any.

Thoughts?

Tim Wood
Owner

Yeah, there's no way to know about people's own language files, but I think we can document the upgrade path and what was depreciated from 1.5 to 1.6.

I think inheriting from english is a good idea. It gives the idea of a solid base, unlike how it currently acts, where it depends on the previous language. It will certainly shrink down this file too.

https://github.com/timrwood/moment/blob/master/lang/en-gb.js

Tim Wood timrwood referenced this pull request from a commit
Tim Wood timrwood remove am/AM/pm/PM from meridiem
Changing to a function.
#222 #228
b34ba94
Tim Wood
Owner

The pull request got botched, so I updated everything manually. Can you double check that the Chinese calendar day tests are correct?

b34ba94#L20R150
b34ba94#L21R150

Rocky Meza
Tim Wood
Owner

Yeah, they pass, but I kinda went about it backwards, copy/pasting the results of the test back into the unit tests themselves. If it all looks good to you, I'll close this out.

Tim Wood timrwood closed this
Rocky Meza

fine by me

Rocky Meza rockymeza referenced this pull request
Closed

Release 1.6.0 discussion #268

jimmyye

There is a bug in the meridiem function.

            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 "晚上";
                }
            },

When 11:31 am, it should be "中午" (noon), but it becomes "下午" (afternoon).
&& minute < 30 is wrong and unnecessary because noon means 11:00 to 13:00 in China.
This should work:

            meridiem : function (hour, minute, isLower) {
                if (hour < 9) {
                    return "早上";
                } else if (hour < 11) {
                    return "上午";
                } else if (hour < 13) {
                    return "中午";
                } else if (hour < 18) {
                    return "下午";
                } else {
                    return "晚上";
                }
            },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 23, 2012
  1. Rocky Meza

    Fixed the meridiem value for Chinese.

    rockymeza authored
    In Chinese, there are more values for the meridiem value than just AM
    and PM.  There are values that mean morning, before noon, noon,
    afternoon, and night time.  I had to modify moment.js to handle a
    callback or default to the previous behavior.
  2. Rocky Meza
This page is out of date. Refresh to see the latest.
6 lang/ca.js
View
@@ -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';
6 lang/da.js
View
@@ -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',
6 lang/de.js
View
@@ -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",
6 lang/en-gb.js
View
@@ -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',
6 lang/es.js
View
@@ -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';
6 lang/eu.js
View
@@ -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]',
6 lang/fr.js
View
@@ -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',
6 lang/gl.js
View
@@ -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';
6 lang/it.js
View
@@ -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',
9 lang/kr.js
View
@@ -11,12 +11,9 @@
LLL : "YYYY년 MMMM D일 LT",
LLLL : "YYYY년 MMMM D일 dddd LT"
},
- meridiem : {
- AM : '오전',
- am : '오전',
- PM : '오후',
- pm : '오후'
- },
+ meridiem : function (hour, minute, upperCase) {
+ return hour > 11 ? '오후' : '오전' ;
+ },
calendar : {
sameDay : '오늘 LT',
nextDay : '내일 LT',
6 lang/nb.js
View
@@ -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',
6 lang/nl.js
View
@@ -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',
6 lang/pl.js
View
@@ -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',
6 lang/pt.js
View
@@ -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',
6 lang/sv.js
View
@@ -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',
6 lang/tr.js
View
@@ -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',
17 lang/zh-cn.js
View
@@ -11,11 +11,18 @@
LLL : "D MMMM YYYY LT",
LLLL : "dddd, D MMMM YYYY LT"
},
- meridiem : {
- AM : '上午',
- am : '上午',
- PM : '下午',
- pm : '下午'
+ meridiem : function (hour, minute, upperCase) {
+ 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',
19 lang/zh-tw.js
View
@@ -11,11 +11,18 @@
LLL : "D MMMM YYYY LT",
LLLL : "dddd, D MMMM YYYY LT"
},
- meridiem : {
- AM : '上午',
- am : '上午',
- PM : '下午',
- pm : '下午'
+ meridiem : function (hour, minute, upperCase) {
+ 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',
@@ -53,4 +60,4 @@
if (typeof window !== 'undefined' && this.moment && this.moment.lang) {
this.moment.lang('zh-tw', lang);
}
-}());
+}());
12 moment.js
View
@@ -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;
@@ -500,7 +500,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) {
@@ -523,12 +523,6 @@
LLL : "MMMM D YYYY LT",
LLLL : "dddd, MMMM D YYYY LT"
},
- meridiem : {
- AM : 'AM',
- am : 'am',
- PM : 'PM',
- pm : 'pm'
- },
calendar : {
sameDay : '[Today at] LT',
nextDay : '[Tomorrow at] LT',
31 test/lang/zh-cn.js
View
@@ -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();
},
@@ -204,5 +204,24 @@ 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();
+ },
+
+ "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();
}
};
33 test/lang/zh-tw.js
View
@@ -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();
},
@@ -204,5 +204,24 @@ 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();
+ },
+
+ "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();
}
-};
+};
Something went wrong with that request. Please try again.