Skip to content

Commit

Permalink
Fixing bug where moment.utc(isostringwithoutzone) does not parse as utc
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Apr 25, 2012
1 parent 3271ddc commit a538306
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion moment.js
Expand Up @@ -585,7 +585,9 @@
if (isArray(input)) {
return new Moment(new Date(Date.UTC.apply({}, input)), true);
}
return (format && input) ? moment(input + ' +00:00', format + ' Z').utc() : moment(input).utc();
return (format && input) ?
moment(input + ' +0000', format + ' Z').utc() :
moment(parseTokenTimezone.exec(input) ? input : input + '+0000').utc();
};

// creating with unix timestamp (in seconds)
Expand Down
14 changes: 14 additions & 0 deletions test/moment/utc.js
Expand Up @@ -42,6 +42,20 @@ exports.utc = {
test.equal(m.date(), 2, "the day should be correct for utc parsing iso");
test.equal(m.hours(), 3, "the hours should be correct for utc parsing iso");

test.done();
},

"creating with utc without timezone" : function(test) {
test.expect(4);

var m = moment.utc("2012-01-02T08:20:00");
test.equal(m.date(), 2, "the day should be correct for utc parse without timezone");
test.equal(m.hours(), 8, "the hours should be correct for utc parse without timezone");

m = moment.utc("2012-01-02T08:20:00+09:00");
test.equal(m.date(), 1, "the day should be correct for utc parse with timezone");
test.equal(m.hours(), 23, "the hours should be correct for utc parse with timezone");

test.done();
}
};

0 comments on commit a538306

Please sign in to comment.