]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Properly clone moment objects, that were improperly cloned before
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 13 Jan 2014 01:44:02 +0000 (17:44 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 14 Jan 2014 07:16:42 +0000 (23:16 -0800)
moment.js

index 438533c38bb209554a7fa07e9e9cefbc7f15b0cd..87a10cc56cf1cb976908d0b65c30663dd534e518 100644 (file)
--- a/moment.js
+++ b/moment.js
         // internal storage for language config files
         languages = {},
 
+        // moment internal properties
+        momentProperties = {
+            _isAMomentObject: null,
+            _i : null,
+            _f : null,
+            _l : null,
+            _strict : null,
+            _isUTC : null,
+            _offset : null,  // optional. Combine with _isUTC
+            _pf : null,
+            _lang : null  // optional
+        },
+
         // check for nodeJS
         hasModule = (typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'),
 
         return a;
     }
 
+    function cloneMoment(m) {
+        var result = {};
+        for (var i in m) {
+            if (m.hasOwnProperty(i) && momentProperties.hasOwnProperty(i)) {
+                result[i] = m[i];
+            }
+        }
+
+        return result;
+    }
+
     function absRound(number) {
         if (number < 0) {
             return Math.ceil(number);
         }
 
         if (moment.isMoment(input)) {
-            config = extend({}, input);
+            config = cloneMoment(input);
 
             config._d = new Date(+input._d);
         } else if (format) {
             lang = undefined;
         }
         return makeMoment({
+            _isAMomentObject: true,
             _i : input,
             _f : format,
             _l : lang,
 
     // compare moment object
     moment.isMoment = function (obj) {
-        return obj instanceof Moment;
+        return obj instanceof Moment ||
+            (obj != null &&  obj.hasOwnProperty('_isAMomentObject'));
     };
 
     // for typechecking Duration objects