]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add moment.duration.toString()
authorIskren Chernev <iskren.chernev@gmail.com>
Wed, 20 Aug 2014 20:02:43 +0000 (23:02 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 20 Aug 2014 21:52:50 +0000 (00:52 +0300)
moment.js
test/moment/duration.js

index 77ed01a47308f501230f5cbc88e9dd2b0455d5c7..1b6457da0e8d9f519c682d233d54bd2937153d9e 100644 (file)
--- a/moment.js
+++ b/moment.js
         }
     });
 
+    moment.duration.fn.toString = moment.duration.fn.toISOString;
+
     function makeDurationGetter(name) {
         moment.duration.fn[name] = function () {
             return this._data[name];
index fcb07dbb6d7b56cc80356f75692bcf453808fe76..2e6e483f11059b8b1d3fd23e7be27cb5ccfe5f85 100644 (file)
@@ -293,6 +293,17 @@ exports.duration = {
         test.done();
     },
 
+    'toString acts as toISOString' : function (test) {
+        test.expect(6);
+        test.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toString(), 'P1Y2M3DT4H5M6S', 'all fields');
+        test.equal(moment.duration({M: -1}).toString(), '-P1M', 'one month ago');
+        test.equal(moment.duration({m: -1}).toString(), '-PT1M', 'one minute ago');
+        test.equal(moment.duration({s: -0.5}).toString(), '-PT0.5S', 'one half second ago');
+        test.equal(moment.duration({y: -0.5, M: 1}).toString(), '-P5M', 'a month after half a year ago');
+        test.equal(moment.duration({}).toString(), 'P0D', 'zero duration');
+        test.done();
+    },
+
     'toIsoString deprecation' : function (test) {
         test.equal(moment.duration({}).toIsoString(), moment.duration({}).toISOString(), 'toIsoString delegates to toISOString');
         test.done();