From 274e83ca00c74d0b48b04dadf503978cbce9ade5 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Fri, 26 Dec 2014 12:27:05 +0200 Subject: [PATCH] Add meridiemHour to locales that need it --- locale/hi.js | 18 ++++++++++++++---- locale/id.js | 14 +++++++++++--- locale/mr.js | 18 ++++++++++++++---- locale/ms-my.js | 14 +++++++++++--- locale/ne.js | 16 +++++++++++++--- locale/ta.js | 44 +++++++++++++++++++++++++++++--------------- locale/zh-cn.js | 16 +++++++++++++--- locale/zh-tw.js | 14 +++++++++++--- test/locale/hi.js | 16 +++++++++++++++- test/locale/id.js | 14 ++++++++++++++ test/locale/mr.js | 14 ++++++++++++++ test/locale/ms-my.js | 14 ++++++++++++++ test/locale/ne.js | 14 ++++++++++++++ test/locale/ta.js | 19 +++++++++++++++++-- test/locale/zh-cn.js | 14 ++++++++++++++ test/locale/zh-tw.js | 14 ++++++++++++++ 16 files changed, 232 insertions(+), 41 deletions(-) diff --git a/locale/hi.js b/locale/hi.js index 5e39a81a8..173c4ee07 100644 --- a/locale/hi.js +++ b/locale/hi.js @@ -85,10 +85,20 @@ }, // Hindi notation for meridiems are quite fuzzy in practice. While there exists // a rigid notion of a 'Pahar' it is not used as rigidly in modern Hindi. - meridiemParse: /रात|सुबह|दोपहर|शाम|रात/, - isPM: function (input) { - // TODO: This is incorrect (look at cutoffs). We need a better isPM interface. - return /^(दोपहर|शाम|रात)$/.test(input); + meridiemParse: /रात|सुबह|दोपहर|शाम/, + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'रात') { + return hour < 4 ? hour : hour + 12; + } else if (meridiem === 'सुबह') { + return hour; + } else if (meridiem === 'दोपहर') { + return hour >= 10 ? hour : hour + 12; + } else if (meridiem === 'शाम') { + return hour + 12; + } }, meridiem : function (hour, minute, isLower) { if (hour < 4) { diff --git a/locale/id.js b/locale/id.js index a4438a3a7..fe0484971 100644 --- a/locale/id.js +++ b/locale/id.js @@ -27,9 +27,17 @@ LLLL : 'dddd, D MMMM YYYY [pukul] LT' }, meridiemParse: /pagi|siang|sore|malam/, - isPM: function (input) { - // TODO: This is incorrect (look at cutoffs). - return /^(siang|sore|malam)$/.test(input); + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'pagi') { + return hour; + } else if (meridiem === 'siang') { + return hour >= 11 ? hour : hour + 12; + } else if (meridiem === 'sore' || meridiem === 'malam') { + return hour + 12; + } }, meridiem : function (hours, minutes, isLower) { if (hours < 11) { diff --git a/locale/mr.js b/locale/mr.js index 28cc5f5b5..93f0eea1d 100644 --- a/locale/mr.js +++ b/locale/mr.js @@ -83,10 +83,20 @@ return symbolMap[match]; }); }, - meridiemParse: /रात्री|सकाळी|दुपारी|सायंकाळी|रात्री/, - isPM : function (input) { - // TODO: This is wrong. - return /^(दुपारी|सायंकाळी|रात्री)$/.test(input); + meridiemParse: /रात्री|सकाळी|दुपारी|सायंकाळी/, + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'रात्री') { + return hour < 4 ? hour : hour + 12; + } else if (meridiem === 'सकाळी') { + return hour; + } else if (meridiem === 'दुपारी') { + return hour >= 10 ? hour : hour + 12; + } else if (meridiem === 'सायंकाळी') { + return hour + 12; + } }, meridiem: function (hour, minute, isLower) { diff --git a/locale/ms-my.js b/locale/ms-my.js index ab60c3f62..56d5e9195 100644 --- a/locale/ms-my.js +++ b/locale/ms-my.js @@ -26,9 +26,17 @@ LLLL : 'dddd, D MMMM YYYY [pukul] LT' }, meridiemParse: /pagi|tengahari|petang|malam/, - isPM: function (input) { - // TODO: This is wrong. - return /^(tengahari|petang|malam)$/.test(input); + meridiemHour: function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'pagi') { + return hour; + } else if (meridiem === 'tengahari') { + return hour >= 11 ? hour : hour + 12; + } else if (meridiem === 'petang' || meridiem === 'malam') { + return hour + 12; + } }, meridiem : function (hours, minutes, isLower) { if (hours < 11) { diff --git a/locale/ne.js b/locale/ne.js index 87f4fddfc..eb25ebe20 100644 --- a/locale/ne.js +++ b/locale/ne.js @@ -61,9 +61,19 @@ }); }, meridiemParse: /राती|बिहान|दिउँसो|बेलुका|साँझ|राती/, - isPM : function (input) { - // TODO: This is wrong. - return /^(दिउँसो|बेलुका|साँझ|राती)$/.test(input); + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'राती') { + return hour < 3 ? hour : hour + 12; + } else if (meridiem === 'बिहान') { + return hour; + } else if (meridiem === 'दिउँसो') { + return hour >= 10 ? hour : hour + 12; + } else if (meridiem === 'बेलुका' || meridiem === 'साँझ') { + return hour + 12; + } }, meridiem : function (hour, minute, isLower) { if (hour < 3) { diff --git a/locale/ta.js b/locale/ta.js index 95179b990..8c86b4bfb 100644 --- a/locale/ta.js +++ b/locale/ta.js @@ -90,22 +90,36 @@ // refer http://ta.wikipedia.org/s/1er1 - - // TODO: This is pretty wrong (when hour is equal to 6 10, 14, 18, 20, - // 24 (0). Also it doesn't split at 12 (noon). + meridiemParse: /யாமம்|வைகறை|காலை|நண்பகல்|எற்பாடு|மாலை/, meridiem : function (hour, minute, isLower) { - if (hour >= 6 && hour <= 10) { - return ' காலை'; - } else if (hour >= 10 && hour <= 14) { - return ' நண்பகல்'; - } else if (hour >= 14 && hour <= 18) { - return ' எற்பாடு'; - } else if (hour >= 18 && hour <= 20) { - return ' மாலை'; - } else if (hour >= 20 && hour <= 24) { - return ' இரவு'; - } else if (hour >= 0 && hour <= 6) { - return ' வைகறை'; + if (hour < 2) { + return ' யாமம்'; + } else if (hour < 6) { + return ' வைகறை'; // வைகறை + } else if (hour < 10) { + return ' காலை'; // காலை + } else if (hour < 14) { + return ' நண்பகல்'; // நண்பகல் + } else if (hour < 18) { + return ' எற்பாடு'; // எற்பாடு + } else if (hour < 22) { + return ' மாலை'; // மாலை + } else { + return ' யாமம்'; + } + }, + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === 'யாமம்') { + return hour < 2 ? hour : hour + 12; + } else if (meridiem === 'வைகறை' || meridiem === 'காலை') { + return hour; + } else if (meridiem === 'நண்பகல்') { + return hour >= 10 ? hour : hour + 12; + } else { + return hour + 12; } }, week : { diff --git a/locale/zh-cn.js b/locale/zh-cn.js index e9421b16e..da834165b 100644 --- a/locale/zh-cn.js +++ b/locale/zh-cn.js @@ -31,9 +31,19 @@ llll : 'YYYY年MMMD日ddddLT' }, meridiemParse: /凌晨|早上|上午|中午|下午|晚上/, - isPM: function (input) { - // TODO: This is wrong. - return /^(中午|下午|晚上)$/.test(input); + meridiemHour: function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === '凌晨' || meridiem === '早上' || + meridiem === '上午') { + return hour; + } else if (meridiem === '下午' || meridiem === '晚上') { + return hour + 12; + } else { + // '中午' + return hour >= 11 ? hour : hour + 12; + } }, meridiem : function (hour, minute, isLower) { var hm = hour * 100 + minute; diff --git a/locale/zh-tw.js b/locale/zh-tw.js index 306dc0e69..75c974d11 100644 --- a/locale/zh-tw.js +++ b/locale/zh-tw.js @@ -30,9 +30,17 @@ llll : 'YYYY年MMMD日ddddLT' }, meridiemParse: /早上|上午|中午|下午|晚上/, - isPM: function (input) { - // TODO: This is wrong. - return /^(中午|下午|晚上)$/.test(input); + meridiemHour : function (hour, meridiem) { + if (hour === 12) { + hour = 0; + } + if (meridiem === '早上' || meridiem === '上午') { + return hour; + } else if (meridiem === '中午') { + return hour >= 11 ? hour : hour + 12; + } else if (meridiem === '下午' || meridiem === '晚上') { + return hour + 12; + } }, meridiem : function (hour, minute, isLower) { var hm = hour * 100 + minute; diff --git a/test/locale/hi.js b/test/locale/hi.js index 2326bbda6..059472a32 100644 --- a/test/locale/hi.js +++ b/test/locale/hi.js @@ -230,7 +230,7 @@ exports['locale:hi'] = { test.done(); }, - 'meridiem' : function (test) { + 'meridiem invariant' : function (test) { test.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात', 'before dawn'); test.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सुबह', 'morning'); test.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दोपहर', 'during day'); @@ -365,6 +365,20 @@ exports['locale:hi'] = { test.done(); }, + 'meridiem' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/id.js b/test/locale/id.js index e96dcef79..5df24a28b 100644 --- a/test/locale/id.js +++ b/test/locale/id.js @@ -308,6 +308,20 @@ exports['locale:id'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/mr.js b/test/locale/mr.js index b69ed0c06..a5cf043cb 100644 --- a/test/locale/mr.js +++ b/test/locale/mr.js @@ -365,6 +365,20 @@ exports['locale:mr'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/ms-my.js b/test/locale/ms-my.js index 0f25e9b97..059b60c7a 100644 --- a/test/locale/ms-my.js +++ b/test/locale/ms-my.js @@ -350,6 +350,20 @@ exports['locale:ms-my'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'lenient ordinal parsing of number' : function (test) { var i, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/ne.js b/test/locale/ne.js index 16b0c4d9d..a7b261d43 100644 --- a/test/locale/ne.js +++ b/test/locale/ne.js @@ -364,6 +364,20 @@ exports['locale:ne'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/ta.js b/test/locale/ta.js index 4974cef34..964941c6f 100644 --- a/test/locale/ta.js +++ b/test/locale/ta.js @@ -313,12 +313,13 @@ exports['locale:ta'] = { }, 'meridiem' : function (test) { + test.equal(moment([2011, 2, 23, 0, 30]).format('a'), ' யாமம்', '(after) midnight'); test.equal(moment([2011, 2, 23, 2, 30]).format('a'), ' வைகறை', 'before dawn'); test.equal(moment([2011, 2, 23, 9, 30]).format('a'), ' காலை', 'morning'); - test.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' நண்பகல்', 'during day'); + test.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' எற்பாடு', 'during day'); test.equal(moment([2011, 2, 23, 17, 30]).format('a'), ' எற்பாடு', 'evening'); test.equal(moment([2011, 2, 23, 19, 30]).format('a'), ' மாலை', 'late evening'); - test.equal(moment([2011, 2, 23, 21, 20]).format('a'), ' இரவு', 'night'); + test.equal(moment([2011, 2, 23, 23, 30]).format('a'), ' யாமம்', '(before) midnight'); test.done(); }, @@ -351,6 +352,20 @@ exports['locale:ta'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/zh-cn.js b/test/locale/zh-cn.js index 45057ae47..230483290 100644 --- a/test/locale/zh-cn.js +++ b/test/locale/zh-cn.js @@ -340,6 +340,20 @@ exports['locale:zh-cn'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { diff --git a/test/locale/zh-tw.js b/test/locale/zh-tw.js index 7e1f76b7e..0a6fb941b 100644 --- a/test/locale/zh-tw.js +++ b/test/locale/zh-tw.js @@ -338,6 +338,20 @@ exports['locale:zh-tw'] = { test.done(); }, + 'meridiem invariant' : function (test) { + var h, m, t1, t2; + for (h = 0; h < 24; ++h) { + for (m = 0; m < 60; m += 15) { + t1 = moment.utc([2000, 0, 1, h, m]); + t2 = moment(t1.format('A h:mm'), 'A h:mm'); + test.equal(t2.format('HH:mm'), t1.format('HH:mm'), + 'meridiem at ' + t1.format('HH:mm')); + } + } + + test.done(); + }, + 'strict ordinal parsing' : function (test) { var i, ordinalStr, testMoment; for (i = 1; i <= 31; ++i) { -- 2.47.2