From 531ff492fdbf46da739a79506c9800d6fe450558 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Mon, 3 Jun 2013 10:52:32 -0700 Subject: [PATCH] making auto iso8601 ignore 'T' if it is not in the input string #804 --- moment.js | 9 ++++++--- test/moment/create.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/moment.js b/moment.js index 54b84c9e2d..51b92be0b2 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 9865002163..c08536f36a 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 = [