From: Dylan Ross Date: Sun, 3 Aug 2014 05:15:34 +0000 (-0600) Subject: Implemented toJSON function on Duration so JSON.stringify returns the ISO string... X-Git-Tag: 2.9.0~18^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b69f2e68e519ca408d1422e4115ee04902a62088;p=thirdparty%2Fmoment.git Implemented toJSON function on Duration so JSON.stringify returns the ISO string representation of the duration --- diff --git a/moment.js b/moment.js index fe5717311..dbcfc4002 100644 --- a/moment.js +++ b/moment.js @@ -2880,6 +2880,10 @@ localeData : function () { return this._locale; + }, + + toJSON : function () { + return this.toISOString(); } }); diff --git a/test/moment/duration.js b/test/moment/duration.js index a3bb9c4ac..b8928cfba 100644 --- a/test/moment/duration.js +++ b/test/moment/duration.js @@ -622,6 +622,14 @@ exports.duration = { test.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds'); test.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute'); + test.done(); + }, + + "JSON.stringify duration" : function (test) { + var d = moment.duration(1024, 'h'); + + test.expect(1); + test.equal(JSON.stringify(d), '"' + d.toISOString() + '"', "JSON.stringify on duration should return ISO string"); test.done(); }