From: Tim Wood Date: Mon, 20 May 2013 15:18:15 +0000 (-0700) Subject: Moving isPM check to the language object so it can be overwritten by different languages X-Git-Tag: 2.1.0~30^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b63a8d80e4dfbfa6de0fb684c022cbd5c29c5df8;p=thirdparty%2Fmoment.git Moving isPM check to the language object so it can be overwritten by different languages --- diff --git a/moment.js b/moment.js index 0bb255cf5..3c3099022 100644 --- a/moment.js +++ b/moment.js @@ -487,6 +487,10 @@ return output; }, + isPM : function (input) { + return ((input + '').toLowerCase()[0] === 'p'); + }, + meridiem : function (hours, minutes, isLower) { if (hours > 11) { return isLower ? 'pm' : 'PM'; @@ -741,7 +745,7 @@ // AM / PM case 'a' : // fall through to A case 'A' : - config._isPm = ((input + '').toLowerCase() === 'pm'); + config._isPm = getLangDefinition(config._l).isPM(input); break; // 24 HOUR case 'H' : // fall through to hh diff --git a/test/moment/create.js b/test/moment/create.js index c932732f5..03e083242 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -123,9 +123,12 @@ exports.create = { }, "matching am/pm" : function(test) { - test.expect(1); + test.expect(4); test.equal(moment('2012-09-03T03:00PM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly even if the input string contains other letters'); + test.equal(moment('2012-09-03T03:00P.M.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly even if the input string contains other letters'); + test.equal(moment('2012-09-03T03:00pm', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly even if the input string contains other letters'); + test.equal(moment('2012-09-03T03:00p.m.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly even if the input string contains other letters'); test.done(); },