Permalink
Browse files

Properly clone moment objects, that were improperly cloned before

  • Loading branch information...
1 parent 90de2d3 commit c83785b153577c00f614fc5bc877a87d6b96729f @ichernev committed Jan 13, 2014
Showing with 28 additions and 2 deletions.
  1. +28 −2 moment.js
View
@@ -27,6 +27,19 @@
// 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'),
@@ -356,6 +369,17 @@
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);
@@ -1530,7 +1554,7 @@
}
if (moment.isMoment(input)) {
- config = extend({}, input);
+ config = cloneMoment(input);
config._d = new Date(+input._d);
} else if (format) {
@@ -1552,6 +1576,7 @@
lang = undefined;
}
return makeMoment({
+ _isAMomentObject: true,
_i : input,
_f : format,
_l : lang,
@@ -1687,7 +1712,8 @@
// compare moment object
moment.isMoment = function (obj) {
- return obj instanceof Moment;
+ return obj instanceof Moment ||
+ (obj != null && obj.hasOwnProperty('_isAMomentObject'));
};
// for typechecking Duration objects

0 comments on commit c83785b

Please sign in to comment.