Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cced3b6

Browse files
committedMay 6, 2015
fix(merge): treat dates as atomic values instead of objects.
Makes angular.merge copy dates correctly. Closes #11720
1 parent b2ae35c commit cced3b6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

‎src/Angular.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,12 @@ function baseExtend(dst, objs, deep) {
337337
var src = obj[key];
338338

339339
if (deep && isObject(src)) {
340-
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
341-
baseExtend(dst[key], [src], true);
340+
if (isDate(src)) {
341+
dst[key] = new Date(src.valueOf());
342+
} else {
343+
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
344+
baseExtend(dst[key], [src], true);
345+
}
342346
} else {
343347
dst[key] = src;
344348
}

‎test/AngularSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,16 @@ describe('angular', function() {
405405
// make sure we retain the old key
406406
expect(hashKey(dst)).toEqual(h);
407407
});
408+
409+
410+
it('should copy dates by reference', function() {
411+
var src = { date: new Date() };
412+
var dst = {};
413+
414+
extend(dst, src);
415+
416+
expect(dst.date).toBe(src.date);
417+
});
408418
});
409419

410420

@@ -472,6 +482,18 @@ describe('angular', function() {
472482
});
473483
expect(dst.foo).not.toBe(src.foo);
474484
});
485+
486+
487+
it('should copy dates by value', function() {
488+
var src = { date: new Date() };
489+
var dst = {};
490+
491+
merge(dst, src);
492+
493+
expect(dst.date).not.toBe(src.date);
494+
expect(isDate(dst.date)).toBeTruthy();
495+
expect(dst.date.valueOf()).toEqual(src.date.valueOf());
496+
});
475497
});
476498

477499

0 commit comments

Comments
 (0)
This repository has been archived.