From: Tim Wood Date: Mon, 3 Jun 2013 17:52:32 +0000 (-0700) Subject: making auto iso8601 ignore 'T' if it is not in the input string #804 X-Git-Tag: 2.1.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=531ff492fdbf46da739a79506c9800d6fe450558;p=thirdparty%2Fmoment.git making auto iso8601 ignore 'T' if it is not in the input string #804 --- diff --git a/moment.js b/moment.js index 54b84c9e2..51b92be0b 100644 --- a/moment.js +++ b/moment.js @@ -889,9 +889,12 @@ // date from iso format function makeDateFromString(config) { var i, - string = config._i; - if (isoRegex.exec(string)) { - config._f = 'YYYY-MM-DDT'; + string = config._i, + match = isoRegex.exec(string); + + if (match) { + // match[2] should be "T" or undefined + config._f = 'YYYY-MM-DD' + (match[2] || " "); for (i = 0; i < 4; i++) { if (isoTimes[i][1].exec(string)) { config._f += isoTimes[i][0]; diff --git a/test/moment/create.js b/test/moment/create.js index 986500216..c08536f36 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -353,6 +353,24 @@ exports.create = { test.done(); }, + "parsing iso with T" : function(test) { + test.expect(9); + + test.equal(moment('2011-10-08T18')._f, "YYYY-MM-DDTHH", "should include 'T' in the format"); + test.equal(moment('2011-10-08T18:20')._f, "YYYY-MM-DDTHH:mm", "should include 'T' in the format"); + test.equal(moment('2011-10-08T18:20:13')._f, "YYYY-MM-DDTHH:mm:ss", "should include 'T' in the format"); + test.equal(moment('2011-10-08T18:20:13.321')._f, "YYYY-MM-DDTHH:mm:ss.S", "should include 'T' in the format"); + + test.equal(moment('2011-10-08 18')._f, "YYYY-MM-DD HH", "should not include 'T' in the format"); + test.equal(moment('2011-10-08 18:20')._f, "YYYY-MM-DD HH:mm", "should not include 'T' in the format"); + test.equal(moment('2011-10-08 18:20:13')._f, "YYYY-MM-DD HH:mm:ss", "should not include 'T' in the format"); + test.equal(moment('2011-10-08 18:20:13.321')._f, "YYYY-MM-DD HH:mm:ss.S", "should not include 'T' in the format"); + + test.ok(moment("2013-04-23 15:23:47 UTC").isValid(), "including a trailing UTC in the input should work"); + + test.done(); + }, + "parsing iso Z timezone" : function(test) { var i, formats = [