]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add meridiemHour to locales that need it 1950/head
authorIskren Chernev <iskren.chernev@gmail.com>
Fri, 26 Dec 2014 10:27:05 +0000 (12:27 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 26 Dec 2014 10:36:16 +0000 (12:36 +0200)
16 files changed:
locale/hi.js
locale/id.js
locale/mr.js
locale/ms-my.js
locale/ne.js
locale/ta.js
locale/zh-cn.js
locale/zh-tw.js
test/locale/hi.js
test/locale/id.js
test/locale/mr.js
test/locale/ms-my.js
test/locale/ne.js
test/locale/ta.js
test/locale/zh-cn.js
test/locale/zh-tw.js

index 5e39a81a80acd87b6a5a10c54fcce6931f07bc09..173c4ee07e32fd61caf123bd40c259e07c93cea5 100644 (file)
         },
         // 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) {
index a4438a3a7ae8ccbc3052e52746f99ffc7654be1a..fe04849711434b39e41ed91034157038a2b1b84b 100644 (file)
             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) {
index 28cc5f5b5eb7add6b2cab2122ba96b03e363038f..93f0eea1de1831cd48d37312b9dcca84221319f9 100644 (file)
                 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)
         {
index ab60c3f621d1927dc6cf9ee1fb2faec25383e91b..56d5e9195e966260b830a767a37d2f9e85b19687 100644 (file)
             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) {
index 87f4fddfcf3a2e7478ef23d0cf38f0dc797b9700..eb25ebe2003dc2ca00b14223bd10c269e3b7d51a 100644 (file)
             });
         },
         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) {
index 95179b990648553439e25c88382d0d7f01c3fde8..8c86b4bfba1a4756aa67c5d36a48123b89fc7535 100644 (file)
 
 
         // 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 : {
index e9421b16e47a5ae8fc62c4535bc8c81f947890a2..da834165b815cc0b413bebc0eecb733503bee0fd 100644 (file)
             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;
index 306dc0e692ac18707d1b684994647253e1a8a91d..75c974d1148593831244248197a8d874ea449b05 100644 (file)
             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;
index 2326bbda6579d316e3a02d67c1b8a5c7ba2f1abf..059472a32a50ef50adffb14767b50d5c42a514cb 100644 (file)
@@ -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) {
index e96dcef79d7ae756eebfedd04a0063be2423ed23..5df24a28bf988226c330f929a96a494a7e6d5681 100644 (file)
@@ -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) {
index b69ed0c060cb00ce922b976da51d215fbe6a5969..a5cf043cb01ac0f60f002604def203fb46dbae40 100644 (file)
@@ -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) {
index 0f25e9b9766ceec2603db163184fc821e5fbc010..059b60c7a7f05aa76be8ea3e47ace1112a1bc2a9 100644 (file)
@@ -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) {
index 16b0c4d9d35cc40320e20a0f047e9bc00d15adfc..a7b261d438fbca46ba915e777ac727e47d9a91af 100644 (file)
@@ -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) {
index 4974cef3490cb7c8dd5e6de8bf96b4301123d9a6..964941c6f1b8d394fc93f6122a5db36e883958ad 100644 (file)
@@ -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'), ' à®¨à®£à¯\8dபà®\95லà¯\8d', 'during day');
+        test.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' à®\8eà®±à¯\8dபாà®\9fà¯\81', '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) {
index 45057ae4719d6e02c6e550d85d0315d9b7eca7a4..230483290e50c7331b3ccf999fc189c93f58d3d5 100644 (file)
@@ -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) {
index 7e1f76b7eab34fc58e2cb1317097370430a76034..0a6fb941be6783f92865baccef3d3b6c5edd7a26 100644 (file)
@@ -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) {