Skip to content

Commit

Permalink
Fixes #18978, Add support for Date objects to deepCopy.
Browse files Browse the repository at this point in the history
  • Loading branch information
schallm authored and dylans committed Apr 1, 2017
1 parent bf3e3a3 commit 2aa295a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion request/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ define([
sval = source[name];
if(tval !== sval){
if(tval && typeof tval === 'object' && sval && typeof sval === 'object'){
exports.deepCopy(tval, sval);
if(sval instanceof Date){
target[name] = new Date(sval);
}else{
exports.deepCopy(tval, sval);
}
}else{
target[name] = sval;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/request/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
define([
'intern!object',
'intern/chai!assert',
'../../../request/util'
], function (registerSuite, assert, util) {
registerSuite({
name: 'dojo/request/util',

'deepCopy': function () {
var object1 = {
apple: 0,
banana: {
weight: 52,
price: 100,
code: "B12345",
purchased: new Date(2016, 0, 1)
},
cherry: 97
};
var object2 = {
banana: {
price: 200,
code: "B98765",
purchased: new Date(2017, 0, 1)
},
durian: 100
};
util.deepCopy(object1, object2);
assert.strictEqual(object1.banana.weight, 52);
assert.strictEqual(object1.banana.price, 200);
assert.strictEqual(object1.banana.code, "B98765");
assert.equal(object1.banana.purchased.getTime(), new Date(2017, 0, 1).getTime());
}

});
});

0 comments on commit 2aa295a

Please sign in to comment.