From: Tim Wood Date: Wed, 25 Apr 2012 00:17:27 +0000 (-0700) Subject: Fixing bug where moment.utc(isostringwithoutzone) does not parse as utc X-Git-Tag: 1.6.0~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a538306abb396dbf87c8eb2ab33b05a10d64fd55;p=thirdparty%2Fmoment.git Fixing bug where moment.utc(isostringwithoutzone) does not parse as utc #275 --- diff --git a/moment.js b/moment.js index 794f48052..06a15639d 100644 --- a/moment.js +++ b/moment.js @@ -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) diff --git a/test/moment/utc.js b/test/moment/utc.js index 1a0507e73..866bd5472 100644 --- a/test/moment/utc.js +++ b/test/moment/utc.js @@ -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(); } };