From: Iskren Chernev Date: Sat, 27 Sep 2014 21:56:36 +0000 (-0700) Subject: Fix parsing of meridiem in locales that have meridiem X-Git-Tag: 2.9.0~13^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd328d56ed4bcecb809b900380af9910bc4a6815;p=thirdparty%2Fmoment.git Fix parsing of meridiem in locales that have meridiem There were many locales that supported meridiem output, but did not support parsing (meridiemParse and isPM locale keys). Also some locales can not be parsed with a simple isPM function, because the variants are not different around noon. A new isPM function (with new name -- fixPM) is needed that also takes an hour and returns whether you should add 12 hours or not. --- diff --git a/locale/af.js b/locale/af.js index 2fb7adff2..9c7ad95d8 100644 --- a/locale/af.js +++ b/locale/af.js @@ -17,6 +17,10 @@ weekdays : 'Sondag_Maandag_Dinsdag_Woensdag_Donderdag_Vrydag_Saterdag'.split('_'), weekdaysShort : 'Son_Maa_Din_Woe_Don_Vry_Sat'.split('_'), weekdaysMin : 'So_Ma_Di_Wo_Do_Vr_Sa'.split('_'), + meridiemParse: /vm|nm/i, + isPM : function (input) { + return /^nm$/i.test(input); + }, meridiem : function (hours, minutes, isLower) { if (hours < 12) { return isLower ? 'vm' : 'VM'; diff --git a/locale/ar-sa.js b/locale/ar-sa.js index ea7e2f6b4..731f97be3 100644 --- a/locale/ar-sa.js +++ b/locale/ar-sa.js @@ -49,6 +49,10 @@ LLL : 'D MMMM YYYY LT', LLLL : 'dddd D MMMM YYYY LT' }, + meridiemParse: /ص|م/, + isPM : function (input) { + return 'م' === input; + }, meridiem : function (hour, minute, isLower) { if (hour < 12) { return 'ص'; diff --git a/locale/ar.js b/locale/ar.js index d6450087d..828e61876 100644 --- a/locale/ar.js +++ b/locale/ar.js @@ -82,6 +82,10 @@ LLL : 'D MMMM YYYY LT', LLLL : 'dddd D MMMM YYYY LT' }, + meridiemParse: /ص|م/, + isPM : function (input) { + return 'م' === input; + }, meridiem : function (hour, minute, isLower) { if (hour < 12) { return 'ص'; diff --git a/locale/az.js b/locale/az.js index d4d143426..7624feea7 100644 --- a/locale/az.js +++ b/locale/az.js @@ -73,6 +73,10 @@ y : 'bir il', yy : '%d il' }, + meridiemParse: /gecə|səhər|gündüz|axşam/, + isPM : function (input) { + return /^(gündüz|axşam)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'gecə'; diff --git a/locale/be.js b/locale/be.js index 68a6f37cb..d888e21c4 100644 --- a/locale/be.js +++ b/locale/be.js @@ -114,8 +114,10 @@ y : 'год', yy : relativeTimeWithPlural }, - - + meridiemParse: /ночы|раніцы|дня|вечара/, + isPM : function (input) { + return /^(дня|вечара)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'ночы'; diff --git a/locale/bn.js b/locale/bn.js index e9549d993..5b4ab515e 100644 --- a/locale/bn.js +++ b/locale/bn.js @@ -83,6 +83,10 @@ return symbolMap[match]; }); }, + meridiemParse: /রাত|শকাল|দুপুর|বিকেল|রাত/, + isPM: function (input) { + return /^(দুপুর|বিকেল|রাত)$/.test(input); + }, //Bengali is a vast language its spoken //in different forms in various parts of the world. //I have just generalized with most common one used diff --git a/locale/bo.js b/locale/bo.js index cece8d133..b8e7001aa 100644 --- a/locale/bo.js +++ b/locale/bo.js @@ -83,6 +83,10 @@ return symbolMap[match]; }); }, + meridiemParse: /མཚན་མོ|ཞོགས་ཀས|ཉིན་གུང|དགོང་དག|མཚན་མོ/, + isPM: function (input) { + return /^(ཉིན་གུང|དགོང་དག|མཚན་མོ)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'མཚན་མོ'; diff --git a/locale/eo.js b/locale/eo.js index 6a3d097b9..9e3d04569 100644 --- a/locale/eo.js +++ b/locale/eo.js @@ -27,6 +27,10 @@ LLL : 'D[-an de] MMMM, YYYY LT', LLLL : 'dddd, [la] D[-an de] MMMM, YYYY LT' }, + meridiemParse: /[ap]\.t\.m/i, + isPM: function (input) { + return input.charAt(0).toLowerCase() === 'p'; + }, meridiem : function (hours, minutes, isLower) { if (hours > 11) { return isLower ? 'p.t.m.' : 'P.T.M.'; diff --git a/locale/fa.js b/locale/fa.js index ad2087a2e..6d765751c 100644 --- a/locale/fa.js +++ b/locale/fa.js @@ -49,6 +49,10 @@ LLL : 'D MMMM YYYY LT', LLLL : 'dddd, D MMMM YYYY LT' }, + meridiemParse: /قبل از ظهر|بعد از ظهر/, + isPM: function (input) { + return /بعد از ظهر/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 12) { return 'قبل از ظهر'; diff --git a/locale/hi.js b/locale/hi.js index 73deba5b1..5e39a81a8 100644 --- a/locale/hi.js +++ b/locale/hi.js @@ -85,6 +85,11 @@ }, // 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); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'रात'; diff --git a/locale/hu.js b/locale/hu.js index 7eccd1d90..de8cae9c3 100644 --- a/locale/hu.js +++ b/locale/hu.js @@ -63,6 +63,10 @@ LLL : 'YYYY. MMMM D., LT', LLLL : 'YYYY. MMMM D., dddd LT' }, + meridiemParse: /de|du/i, + isPM: function (input) { + return input.charAt(1).toLowerCase() === 'u'; + }, meridiem : function (hours, minutes, isLower) { if (hours < 12) { return isLower === true ? 'de' : 'DE'; diff --git a/locale/hy-am.js b/locale/hy-am.js index 053a845e0..6e2de8ba6 100644 --- a/locale/hy-am.js +++ b/locale/hy-am.js @@ -78,6 +78,10 @@ yy : '%d տարի' }, + meridiemParse: /գիշերվա|առավոտվա|ցերեկվա|երեկոյան/, + isPM: function (input) { + return /^(ցերեկվա|երեկոյան)$/.test(input); + }, meridiem : function (hour) { if (hour < 4) { return 'գիշերվա'; diff --git a/locale/id.js b/locale/id.js index 36a841a61..a4438a3a7 100644 --- a/locale/id.js +++ b/locale/id.js @@ -26,6 +26,11 @@ LLL : 'D MMMM YYYY [pukul] LT', 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); + }, meridiem : function (hours, minutes, isLower) { if (hours < 11) { return 'pagi'; diff --git a/locale/ja.js b/locale/ja.js index 3f55bcfd5..1feb20206 100644 --- a/locale/ja.js +++ b/locale/ja.js @@ -25,6 +25,10 @@ LLL : 'YYYY年M月D日LT', LLLL : 'YYYY年M月D日LT dddd' }, + meridiemParse: /午前|午後/i, + isPM : function (input) { + return input === '午後'; + }, meridiem : function (hour, minute, isLower) { if (hour < 12) { return '午前'; diff --git a/locale/ko.js b/locale/ko.js index 956345bde..8f9396f9a 100644 --- a/locale/ko.js +++ b/locale/ko.js @@ -28,9 +28,6 @@ LLL : 'YYYY년 MMMM D일 LT', LLLL : 'YYYY년 MMMM D일 dddd LT' }, - meridiem : function (hour, minute, isUpper) { - return hour < 12 ? '오전' : '오후'; - }, calendar : { sameDay : '오늘 LT', nextDay : '내일 LT', @@ -57,9 +54,12 @@ }, ordinalParse : /\d{1,2}일/, ordinal : '%d일', - meridiemParse : /(오전|오후)/, + meridiemParse : /오전|오후/, isPM : function (token) { return token === '오후'; + }, + meridiem : function (hour, minute, isUpper) { + return hour < 12 ? '오전' : '오후'; } }); })); diff --git a/locale/ml.js b/locale/ml.js index 38509141c..eb877bb1a 100644 --- a/locale/ml.js +++ b/locale/ml.js @@ -48,6 +48,10 @@ y : 'ഒരു വർഷം', yy : '%d വർഷം' }, + meridiemParse: /രാത്രി|രാവിലെ|ഉച്ച കഴിഞ്ഞ്|വൈകുന്നേരം|രാത്രി/i, + isPM : function (input) { + return /^(ഉച്ച കഴിഞ്ഞ്|വൈകുന്നേരം|രാത്രി)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'രാത്രി'; diff --git a/locale/mr.js b/locale/mr.js index 45c200e8c..28cc5f5b5 100644 --- a/locale/mr.js +++ b/locale/mr.js @@ -83,6 +83,11 @@ return symbolMap[match]; }); }, + meridiemParse: /रात्री|सकाळी|दुपारी|सायंकाळी|रात्री/, + isPM : function (input) { + // TODO: This is wrong. + return /^(दुपारी|सायंकाळी|रात्री)$/.test(input); + }, meridiem: function (hour, minute, isLower) { if (hour < 4) { diff --git a/locale/ms-my.js b/locale/ms-my.js index 09ec280b7..ab60c3f62 100644 --- a/locale/ms-my.js +++ b/locale/ms-my.js @@ -25,6 +25,11 @@ LLL : 'D MMMM YYYY [pukul] LT', 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); + }, meridiem : function (hours, minutes, isLower) { if (hours < 11) { return 'pagi'; diff --git a/locale/ne.js b/locale/ne.js index ceb283411..87f4fddfc 100644 --- a/locale/ne.js +++ b/locale/ne.js @@ -60,6 +60,11 @@ return symbolMap[match]; }); }, + meridiemParse: /राती|बिहान|दिउँसो|बेलुका|साँझ|राती/, + isPM : function (input) { + // TODO: This is wrong. + return /^(दिउँसो|बेलुका|साँझ|राती)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 3) { return 'राती'; diff --git a/locale/sq.js b/locale/sq.js index 415495aa1..9a5bc0989 100644 --- a/locale/sq.js +++ b/locale/sq.js @@ -19,6 +19,10 @@ weekdays : 'E Diel_E Hënë_E Martë_E Mërkurë_E Enjte_E Premte_E Shtunë'.split('_'), weekdaysShort : 'Die_Hën_Mar_Mër_Enj_Pre_Sht'.split('_'), weekdaysMin : 'D_H_Ma_Më_E_P_Sh'.split('_'), + meridiemParse: /PD|MD/, + isPM: function (input) { + return input.charAt(0) === 'M'; + }, meridiem : function (hours, minutes, isLower) { return hours < 12 ? 'PD' : 'MD'; }, diff --git a/locale/ta.js b/locale/ta.js index d0356a3ef..95179b990 100644 --- a/locale/ta.js +++ b/locale/ta.js @@ -91,6 +91,8 @@ // 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). meridiem : function (hour, minute, isLower) { if (hour >= 6 && hour <= 10) { return ' காலை'; diff --git a/locale/th.js b/locale/th.js index e3c54229e..ec9b840b3 100644 --- a/locale/th.js +++ b/locale/th.js @@ -25,6 +25,10 @@ LLL : 'D MMMM YYYY เวลา LT', LLLL : 'วันddddที่ D MMMM YYYY เวลา LT' }, + meridiemParse: /ก่อนเที่ยง|หลังเที่ยง/, + isPM: function (input) { + return input === 'หลังเที่ยง'; + }, meridiem : function (hour, minute, isLower) { if (hour < 12) { return 'ก่อนเที่ยง'; diff --git a/locale/uk.js b/locale/uk.js index 3dce4bcad..84e11ceac 100644 --- a/locale/uk.js +++ b/locale/uk.js @@ -123,6 +123,10 @@ // M. E.: those two are virtually unused but a user might want to implement them for his/her website for some reason + meridiemParse: /ночі|ранку|дня|вечора/, + isPM: function (input) { + return /^(дня|вечора)$/.test(input); + }, meridiem : function (hour, minute, isLower) { if (hour < 4) { return 'ночі'; diff --git a/locale/zh-cn.js b/locale/zh-cn.js index b8a0bd2ea..e9421b16e 100644 --- a/locale/zh-cn.js +++ b/locale/zh-cn.js @@ -30,6 +30,11 @@ lll : 'YYYY年MMMD日LT', llll : 'YYYY年MMMD日ddddLT' }, + meridiemParse: /凌晨|早上|上午|中午|下午|晚上/, + isPM: function (input) { + // TODO: This is wrong. + return /^(中午|下午|晚上)$/.test(input); + }, meridiem : function (hour, minute, isLower) { var hm = hour * 100 + minute; if (hm < 600) { diff --git a/locale/zh-tw.js b/locale/zh-tw.js index b3c4439c7..306dc0e69 100644 --- a/locale/zh-tw.js +++ b/locale/zh-tw.js @@ -29,6 +29,11 @@ lll : 'YYYY年MMMD日LT', llll : 'YYYY年MMMD日ddddLT' }, + meridiemParse: /早上|上午|中午|下午|晚上/, + isPM: function (input) { + // TODO: This is wrong. + return /^(中午|下午|晚上)$/.test(input); + }, meridiem : function (hour, minute, isLower) { var hm = hour * 100 + minute; if (hm < 900) {