]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Implemented toJSON function on Duration so JSON.stringify returns the ISO string...
authorDylan Ross <dylanross@attask.com>
Sun, 3 Aug 2014 05:15:34 +0000 (23:15 -0600)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 24 Dec 2014 21:40:31 +0000 (13:40 -0800)
moment.js
test/moment/duration.js

index fe571731160a269bbfcc513de5c39791a27e7a68..dbcfc400226535c0116d22e00b83443cdbb2b9f5 100644 (file)
--- a/moment.js
+++ b/moment.js
 
         localeData : function () {
             return this._locale;
+        },
+
+        toJSON : function () {
+            return this.toISOString();
         }
     });
 
index a3bb9c4ac9118318b30bdb1aa0216a99a861caa5..b8928cfba86807bc1c8419d10fdfb49343af0e01 100644 (file)
@@ -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();
     }