From: Iskren Chernev Date: Wed, 11 Dec 2013 09:18:48 +0000 (-0800) Subject: Use YYYYYY format in iso string for big and negative years X-Git-Tag: 2.5.0^2~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2458ebb2b2d8afd55ad06bcef785da2fbc99123b;p=thirdparty%2Fmoment.git Use YYYYYY format in iso string for big and negative years --- diff --git a/moment.js b/moment.js index cd6be16d5..da3e0d1dc 100644 --- a/moment.js +++ b/moment.js @@ -1739,7 +1739,12 @@ }, toISOString : function () { - return formatMoment(moment(this).utc(), 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); + var m = moment(this).utc(); + if (0 < m.year() && m.year() <= 9999) { + return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); + } else { + return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); + } }, toArray : function () { diff --git a/test/moment/format.js b/test/moment/format.js index 1207da343..520276937 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -160,9 +160,21 @@ exports.format = { }, "toISOString" : function (test) { + test.expect(4); var date = moment.utc("2012-10-09T20:30:40.678"); test.equal(date.toISOString(), "2012-10-09T20:30:40.678Z", "should output ISO8601 on moment.fn.toISOString"); + + // big years + date = moment.utc("+020123-10-09T20:30:40.678"); + test.equal(date.toISOString(), "+020123-10-09T20:30:40.678Z", "ISO8601 format on big positive year"); + // negative years + date = moment.utc("-000001-10-09T20:30:40.678"); + test.equal(date.toISOString(), "-000001-10-09T20:30:40.678Z", "ISO8601 format on big positive year"); + // big negative years + date = moment.utc("-020123-10-09T20:30:40.678"); + test.equal(date.toISOString(), "-020123-10-09T20:30:40.678Z", "ISO8601 format on big positive year"); + test.done(); },