]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Change duration.toIsoString to duration.toISOString. Closes #1752 1759/head
authorIsaac Cambron <isaac@isaaccambron.com>
Thu, 3 Jul 2014 21:04:15 +0000 (17:04 -0400)
committerIsaac Cambron <isaac@isaaccambron.com>
Thu, 3 Jul 2014 21:04:15 +0000 (17:04 -0400)
moment.js
test/moment/duration.js

index a7cbd43c8ceb2363d3fb98ca6647683bf2d8e6ab..632756872d0a0a988612e1f1121d4d32bd35d31d 100644 (file)
--- a/moment.js
+++ b/moment.js
 
         lang : moment.fn.lang,
 
-        toIsoString : function () {
+        toIsoString : deprecate(
+            "toIsoString() is deprecated. Please use toISOString() instead " +
+            "(notice the capitals)",
+            function () {
+                return this.toISOString();
+            }
+        ),
+
+        toISOString : function () {
             // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
             var years = Math.abs(this.years()),
                 months = Math.abs(this.months()),
index 95dd256baa722e7004733a1ab60b43c829383544..b700445e2dbed7c14a612d65f71d01ffcdf32916 100644 (file)
@@ -284,12 +284,17 @@ exports.duration = {
 
     "serialization to ISO 8601 duration strings" : function (test) {
         test.expect(6);
-        test.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toIsoString(), "P1Y2M3DT4H5M6S", "all fields");
-        test.equal(moment.duration({M: -1}).toIsoString(), "-P1M", "one month ago");
-        test.equal(moment.duration({m: -1}).toIsoString(), "-PT1M", "one minute ago");
-        test.equal(moment.duration({s: -0.5}).toIsoString(), "-PT0.5S", "one half second ago");
-        test.equal(moment.duration({y: -0.5, M: 1}).toIsoString(), "-P5M", "a month after half a year ago");
-        test.equal(moment.duration({}).toIsoString(), "P0D", "zero duration");
+        test.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toISOString(), "P1Y2M3DT4H5M6S", "all fields");
+        test.equal(moment.duration({M: -1}).toISOString(), "-P1M", "one month ago");
+        test.equal(moment.duration({m: -1}).toISOString(), "-PT1M", "one minute ago");
+        test.equal(moment.duration({s: -0.5}).toISOString(), "-PT0.5S", "one half second ago");
+        test.equal(moment.duration({y: -0.5, M: 1}).toISOString(), "-P5M", "a month after half a year ago");
+        test.equal(moment.duration({}).toISOString(), "P0D", "zero duration");
+        test.done();
+    },
+
+    "toIsoString deprecation" : function (test) {
+        test.equal(moment.duration({}).toIsoString(), moment.duration({}).toISOString(), "toIsoString delegates to toISOString");
         test.done();
     },