]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Create valid duration object when null is passed to moment.duration()
authorChasen Le Hara <chasen@chasenlehara.com>
Fri, 19 Dec 2014 08:40:44 +0000 (00:40 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 29 Dec 2014 14:10:56 +0000 (16:10 +0200)
moment.js
test/moment/duration.js

index 19a416929642fb56a2415192d62fffe30fb16d6d..e4fbb6e870ceac87062183eadbaee0a75d3d06c3 100644 (file)
--- a/moment.js
+++ b/moment.js
                 s: parseIso(match[7]),
                 w: parseIso(match[8])
             };
+        } else if (duration == null) {// checks for null or undefined
+            duration = {};
         } else if (typeof duration === 'object' &&
                 ('from' in duration || 'to' in duration)) {
             diffRes = momentsDifference(moment(duration.from), moment(duration.to));
index a640bc41edccb5490d564dbcc36f57e9d480cbc3..af1c0da8438cc5ae791b63e15e416db9dc544f0f 100644 (file)
@@ -62,6 +62,18 @@ exports.duration = {
         test.done();
     },
 
+    'undefined instantiation' : function (test) {
+        test.expect(1);
+        test.equal(moment.duration(undefined).milliseconds(), 0, 'milliseconds');
+        test.done();
+    },
+
+    'null instantiation' : function (test) {
+        test.expect(1);
+        test.equal(moment.duration(null).milliseconds(), 0, 'milliseconds');
+        test.done();
+    },
+
     'instantiation by type' : function (test) {
         test.expect(16);
         test.equal(moment.duration(1, 'years').years(),                 1, 'years');