fix(datepicker): native date adapter not preserving time when cloning (#14691)

When the `NativeDateAdapter` clones a date, it creates the clone only from the year, month and day which means that the clone's time will be different from the source.
This commit is contained in:
Kristiyan Kostadinov
2019-01-04 19:45:04 +02:00
committed by mmalerba
parent 17bb9c3ef5
commit 9e3a77bf94
2 changed files with 7 additions and 1 deletions
@@ -290,6 +290,12 @@ describe('NativeDateAdapter', () => {
expect(adapter.clone(date)).not.toBe(date);
});
it('should preserve time when cloning', () => {
let date = new Date(2017, JAN, 1, 4, 5, 6);
expect(adapter.clone(date)).toEqual(date);
expect(adapter.clone(date)).not.toBe(date);
});
it('should compare dates', () => {
expect(adapter.compareDate(new Date(2017, JAN, 1), new Date(2017, JAN, 2))).toBeLessThan(0);
expect(adapter.compareDate(new Date(2017, JAN, 1), new Date(2017, FEB, 1))).toBeLessThan(0);
+1 -1
View File
@@ -146,7 +146,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
}
clone(date: Date): Date {
return this.createDate(this.getYear(date), this.getMonth(date), this.getDate(date));
return new Date(date.getTime());
}
createDate(year: number, month: number, date: number): Date {