Fixed date time period start/end values check

This commit is contained in:
Ekaterina Chantsova 2025-03-14 11:49:13 +02:00
parent b7a0a800dd
commit babda72b1e

View File

@ -160,22 +160,26 @@ export class DatetimePeriodComponent implements ControlValueAccessor {
private onStartDateChange(startDate: Date) { private onStartDateChange(startDate: Date) {
if (startDate) { if (startDate) {
if (startDate.getTime() > this.maxStartTs) { let startDateTs = startDate.getTime();
this.dateTimePeriodFormGroup.get('startDate').patchValue(new Date(this.maxStartTs), { emitEvent: false }); if (startDateTs > this.maxStartTs) {
startDateTs = this.maxStartTs;
this.dateTimePeriodFormGroup.get('startDate').patchValue(new Date(startDateTs), { emitEvent: false });
} }
if (startDate.getTime() > this.maxStartDateTs) { if (startDateTs > this.maxStartDateTs) {
this.dateTimePeriodFormGroup.get('endDate').patchValue(new Date(startDate.getTime() + this.timeShiftMs), { emitEvent: false }); this.dateTimePeriodFormGroup.get('endDate').patchValue(new Date(startDateTs + this.timeShiftMs), { emitEvent: false });
} }
} }
} }
private onEndDateChange(endDate: Date) { private onEndDateChange(endDate: Date) {
if (endDate) { if (endDate) {
if (endDate.getTime() > this.maxEndTs) { let endDateTs = endDate.getTime();
this.dateTimePeriodFormGroup.get('endDate').patchValue(new Date(this.maxEndTs), { emitEvent: false }); if (endDateTs > this.maxEndTs) {
endDateTs = this.maxEndTs;
this.dateTimePeriodFormGroup.get('endDate').patchValue(new Date(endDateTs), { emitEvent: false });
} }
if (endDate.getTime() < this.minEndDateTs) { if (endDateTs < this.minEndDateTs) {
this.dateTimePeriodFormGroup.get('startDate').patchValue(new Date(endDate.getTime() - this.timeShiftMs), { emitEvent: false }); this.dateTimePeriodFormGroup.get('startDate').patchValue(new Date(endDateTs - this.timeShiftMs), { emitEvent: false });
} }
} }
} }