From dbf504b060cada4b4d173a4ee1bdd4ba513633f1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 1 Nov 2025 21:07:17 +0000 Subject: [PATCH] Replace magic number -1 with named constant for better code clarity Co-authored-by: THoguet <61246905+THoguet@users.noreply.github.com> --- src/app/services/calendar-service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/services/calendar-service.ts b/src/app/services/calendar-service.ts index 30839d7..44cb2f4 100644 --- a/src/app/services/calendar-service.ts +++ b/src/app/services/calendar-service.ts @@ -292,6 +292,9 @@ export class SelectedDates implements SelectedDateInterface { private minDate: Date | null = null; private maxDate: Date | null = null; + // Constant to indicate no valid strategy was found + private static readonly NO_VALID_STRATEGY_HEURISTIC = -1; + update(): void { this.datesSelected = this._datesSelected.slice(); this.grouping(); @@ -524,21 +527,21 @@ export class SelectedDates implements SelectedDateInterface { if (calendarSettingsService.samediMalin()) this.samediMalin(vacationsNumber); while (vacationsNumber.cp > 0) { const result = this.lookForVacation(DayType.CP); - if (result.heuristic === -1) { + if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) { break; } vacationsNumber.cp -= 1; } while (vacationsNumber.rtt > 0) { const result = this.lookForVacation(DayType.RTT); - if (result.heuristic === -1) { + if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) { break; } vacationsNumber.rtt -= 1; } while (vacationsNumber.other > 0) { const result = this.lookForVacation(DayType.OTHER); - if (result.heuristic === -1) { + if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) { break; } vacationsNumber.other -= 1; @@ -723,7 +726,7 @@ export class SelectedDates implements SelectedDateInterface { // Early exit if no candidates if (candidateDays.length === 0) { - return { apply: () => {}, heuristic: -1 }; + return { apply: () => {}, heuristic: SelectedDates.NO_VALID_STRATEGY_HEURISTIC }; } const tempDatesBackup = [...this._datesSelected]; @@ -773,6 +776,6 @@ export class SelectedDates implements SelectedDateInterface { return bestStrategy; } - return { apply: () => {}, heuristic: -1 }; + return { apply: () => {}, heuristic: SelectedDates.NO_VALID_STRATEGY_HEURISTIC }; } }