]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing bug on #297
authorTim Wood <washwithcare@gmail.com>
Tue, 1 May 2012 23:05:41 +0000 (16:05 -0700)
committerTim Wood <washwithcare@gmail.com>
Tue, 1 May 2012 23:05:41 +0000 (16:05 -0700)
moment.js
test/moment/create.js

index 8de508c970dbb94cbb878271be48cbf1f02f592a..87862ff21dddedb0a7ef4ed09ba9c8973bfd1468 100644 (file)
--- a/moment.js
+++ b/moment.js
         // AM / PM
         case 'a' : // fall through to A
         case 'A' :
-            config.isPm = (input.toLowerCase() === 'pm');
+            config.isPm = ((input + '').toLowerCase() === 'pm');
             break;
         // 24 HOUR
         case 'H' : // fall through to hh
index 25510b69714e20ad54982e695359bdd6d927c76c..05ddf93e5a97c6aac05b1df6c623eebe75449f98 100644 (file)
@@ -64,6 +64,17 @@ exports.create = {
         test.done();
     },
 
+    "string with format dropped am/pm bug" : function(test) {
+        moment.lang('en');
+        test.expect(3);
+        
+        test.equal(moment('05/1/2012', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
+        test.equal(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
+        test.equal(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
+
+        test.done();
+    },
+
     "string with format" : function(test) {
         moment.lang('en');
         var a = [