Skip to content

Commit

Permalink
making auto iso8601 ignore 'T' if it is not in the input string #804
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Jun 3, 2013
1 parent 5298f15 commit 531ff49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 6 additions & 3 deletions moment.js
Expand Up @@ -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];
Expand Down
18 changes: 18 additions & 0 deletions test/moment/create.js
Expand Up @@ -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 = [
Expand Down

0 comments on commit 531ff49

Please sign in to comment.