mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
mmalerba
parent
17bb9c3ef5
commit
9e3a77bf94
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user