Skip to content

Commit e903b6f

Browse files
fix(date-range-picker): prevent mutating passed date range values
1 parent 19b6865 commit e903b6f

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

projects/igniteui-angular/date-picker/src/date-range-picker/date-range-picker.component.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { By } from '@angular/platform-browser';
88
import { ControlsFunction } from '../../../test-utils/controls-functions.spec';
99
import { UIInteractions } from '../../../test-utils/ui-interactions.spec';
1010
import { HelperTestFunctions } from '../../../test-utils/calendar-helper-utils';
11-
import { CancelableEventArgs, I18N_FORMATTER, WEEKDAYS } from 'igniteui-angular/core';
11+
import { CancelableEventArgs, WEEKDAYS } from 'igniteui-angular/core';
1212
import { IgxDateRangeSeparatorDirective, IgxDateRangeStartComponent } from './date-range-picker-inputs.common';
1313
import { IgxDateTimeEditorDirective } from '../../../directives/src/directives/date-time-editor/date-time-editor.directive';
1414
import { DateRangeType } from 'igniteui-angular/core';
@@ -22,7 +22,7 @@ import { IgxIconComponent } from 'igniteui-angular/icon';
2222
import { registerLocaleData } from "@angular/common";
2323
import localeJa from "@angular/common/locales/ja";
2424
import localeBg from "@angular/common/locales/bg";
25-
import { CalendarDay, BaseFormatter } from 'igniteui-angular/core';
25+
import { CalendarDay } from 'igniteui-angular/core';
2626
import { IgxCalendarComponent, IgxCalendarHeaderTemplateDirective, IgxCalendarHeaderTitleTemplateDirective, IgxCalendarSubheaderTemplateDirective } from 'igniteui-angular/calendar';
2727
import { KeyboardNavigationService } from 'igniteui-angular/calendar/src/calendar/calendar.services';
2828

@@ -50,6 +50,7 @@ const CSS_CLASS_CALENDAR_HEADER_TITLE = '.igx-calendar__header-year';
5050
const CSS_CLASS_CALENDAR_SUBHEADER = '.igx-calendar-picker__dates';
5151
const CSS_CLASS_CALENDAR_HEADER = '.igx-calendar__header';
5252
const CSS_CLASS_CALENDAR_WRAPPER_VERTICAL = 'igx-calendar__wrapper--vertical';
53+
5354
describe('IgxDateRangePicker', () => {
5455
describe('Unit tests: ', () => {
5556
let mockElement: any;
@@ -1067,6 +1068,29 @@ describe('IgxDateRangePicker', () => {
10671068
fixture.detectChanges();
10681069
verifyDateRange();
10691070
});
1071+
1072+
it('should not mutate the time of the passed-in value when opening the picker', fakeAsync(() => {
1073+
const start = new Date(2026, 4, 10, 14, 30, 45);
1074+
const end = new Date(2026, 4, 20, 15, 15, 30);
1075+
dateRange.value = { start, end };
1076+
fixture.detectChanges();
1077+
1078+
dateRange.open();
1079+
tick();
1080+
fixture.detectChanges();
1081+
1082+
expect(start.getHours()).toBe(14);
1083+
expect(start.getMinutes()).toBe(30);
1084+
expect(start.getSeconds()).toBe(45);
1085+
expect(end.getHours()).toBe(15);
1086+
expect(end.getMinutes()).toBe(15);
1087+
expect(end.getSeconds()).toBe(30);
1088+
1089+
dateRange.close();
1090+
tick();
1091+
fixture.detectChanges();
1092+
}));
1093+
10701094
it('should support different input and display formats', () => {
10711095
let inputFormat = 'dd/MM/yy';
10721096
let displayFormat = 'longDate';

projects/igniteui-angular/date-picker/src/date-range-picker/date-range-picker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
475475
@Input()
476476
public get activeDate(): Date {
477477
const today = new Date(new Date().setHours(0, 0, 0, 0));
478-
const dateValue = DateTimeUtil.isValidDate(this._firstDefinedInRange) ? new Date(this._firstDefinedInRange.setHours(0, 0, 0, 0)) : null;
478+
const dateValue = DateTimeUtil.isValidDate(this._firstDefinedInRange) ? new Date(new Date(this._firstDefinedInRange.getTime()).setHours(0, 0, 0, 0)) : null;
479479
return this._activeDate ?? dateValue ?? this._calendar?.activeDate ?? today;
480480
}
481481

0 commit comments

Comments
 (0)