]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Making moment(Date) copy the Date instead of using it directly #592
authorTim Wood <washwithcare@gmail.com>
Fri, 25 Jan 2013 18:08:00 +0000 (10:08 -0800)
committerTim Wood <washwithcare@gmail.com>
Fri, 25 Jan 2013 18:08:00 +0000 (10:08 -0800)
moment.js
test/moment/create.js
test/moment/mutable.js

index 75296b8469ae0756df00622bcc18ed9d52466179..860bb92fc5b71d1137abff826b857e4d2d63c6c4 100644 (file)
--- a/moment.js
+++ b/moment.js
             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);
         }
     }
 
index c5419dea6179879fc37c2e6fffdddaf2f8510663..801a614515fcc26ae6fc1a754828aa65b84e6306 100644 (file)
@@ -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())");
index 4d45c94b187657590be381b98372c5813b3430ed..70f6b0da338b583acc6b57bb84699c03cc97fb0e 100644 (file)
@@ -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() }