diff --git a/components/calendar/date-table.component.ts b/components/calendar/date-table.component.ts index 4b00eb3c7cf..98ddd33b819 100644 --- a/components/calendar/date-table.component.ts +++ b/components/calendar/date-table.component.ts @@ -106,9 +106,12 @@ export class DateTableComponent implements OnInit, OnChanges { } private changeValueFromInside(value: CandyDate): void { - if (this.value !== value) { - this.valueChange.emit(value); - } + // Only change date not change time + const newValue = this.value + .setYear(value.getYear()) + .setMonth(value.getMonth()) + .setDate(value.getDate()); + this.valueChange.emit(newValue); } private makeHeadWeekDays(): WeekDayLabel[] { diff --git a/components/date-picker/nz-date-picker.component.spec.ts b/components/date-picker/nz-date-picker.component.spec.ts index 8de67365b3f..24e91d996d1 100644 --- a/components/date-picker/nz-date-picker.component.spec.ts +++ b/components/date-picker/nz-date-picker.component.spec.ts @@ -642,6 +642,20 @@ describe('NzDatePickerComponent', () => { expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2018-11-11 00:22:33'); })); + it('should not reset time', fakeAsync(() => { + fixtureInstance.nzValue = new Date('2019-08-02 13:03:33'); + fixtureInstance.nzShowTime = true; + fixture.detectChanges(); + openPickerByClickTrigger(); + + dispatchMouseEvent(queryFromOverlay('.ant-calendar-cell > .ant-calendar-date'), 'click'); + + fixture.detectChanges(); + flush(); + fixture.detectChanges(); + expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2019-07-29 13:03:33'); + })); + it('should support nzShowTime.nzFormat', fakeAsync(() => { fixtureInstance.nzShowTime = { nzFormat: 'HH:mm' }; fixture.detectChanges();