From: Tim Wood Date: Fri, 25 Jan 2013 18:08:00 +0000 (-0800) Subject: Making moment(Date) copy the Date instead of using it directly #592 X-Git-Tag: 2.0.0~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbeeeb6819407c160a4a23cb6ca43dd041b04dae;p=thirdparty%2Fmoment.git Making moment(Date) copy the Date instead of using it directly #592 --- diff --git a/moment.js b/moment.js index 75296b846..860bb92fc 100644 --- a/moment.js +++ b/moment.js @@ -828,7 +828,7 @@ config._a = input.slice(0); dateFromArray(config); } else { - config._d = input instanceof Date ? input : new Date(input); + config._d = input instanceof Date ? new Date(+input) : new Date(input); } } diff --git a/test/moment/create.js b/test/moment/create.js index c5419dea6..801a61451 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -49,6 +49,13 @@ exports.create = { test.done(); }, + "date mutation" : function(test) { + test.expect(1); + var a = new Date(); + test.ok(moment(a).toDate() !== a, "the date moment uses should not be the date passed in"); + test.done(); + }, + "moment" : function(test) { test.expect(2); test.ok(moment(moment()).toDate() instanceof Date, "moment(moment())"); diff --git a/test/moment/mutable.js b/test/moment/mutable.js index 4d45c94b1..70f6b0da3 100644 --- a/test/moment/mutable.js +++ b/test/moment/mutable.js @@ -2,7 +2,7 @@ var moment = require("../../moment"); exports.mutable = { "manipulation methods" : function (test) { - + var mutableMethods = { 'year': function (m){ return m.year(2011); }, 'month': function (m){ return m.month(1); }, @@ -24,8 +24,8 @@ exports.mutable = { for (method in mutableMethods) { if (mutableMethods.hasOwnProperty(method)) { - var d = new Date(); - var d2 = mutableMethods[method](moment(d)).toDate(); + var d = moment(); + var d2 = mutableMethods[method](d); test.equal(d, d2, method + "() should be mutable"); } } @@ -34,7 +34,7 @@ exports.mutable = { }, "non mutable methods" : function (test) { - + var nonMutableMethods = { 'sod': function (m){ return m.sod() }, 'eod': function (m){ return m.eod() }