From ca90c59084fea149881b23d72b7ffa7d4eb8e996 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Tue, 1 May 2012 16:05:41 -0700 Subject: [PATCH] Fixing bug on #297 --- moment.js | 2 +- test/moment/create.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/moment.js b/moment.js index 8de508c97..87862ff21 100644 --- a/moment.js +++ b/moment.js @@ -392,7 +392,7 @@ // 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 diff --git a/test/moment/create.js b/test/moment/create.js index 25510b697..05ddf93e5 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -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 = [ -- 2.47.3