From c5ac479915492032e1cf7361b5c4e15ba606731a Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 23 Sep 2026 23:11:10 +0200 Subject: [PATCH] fix(dayplan): sort the trip's dates with an explicit compare ISO dates sort the same as plain strings, but a sort without a compare function reads as an accident to anyone checking it, and SonarCloud flags it as one. The three places that order the trip's dates now say how. --- client/src/store/slices/daysSlice.ts | 2 +- client/src/utils/dayDeleteImpact.ts | 2 +- server/src/nest/days/day-removal.service.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/store/slices/daysSlice.ts b/client/src/store/slices/daysSlice.ts index 5c335b346..4820b2706 100644 --- a/client/src/store/slices/daysSlice.ts +++ b/client/src/store/slices/daysSlice.ts @@ -28,7 +28,7 @@ type DayState = Pick (a.day_number ?? 0) - (b.day_number ?? 0)) - const dates = ordered.map(d => d.date).filter((d): d is string => !!d).sort() + const dates = ordered.map(d => d.date).filter((d): d is string => !!d).sort((a, b) => a.localeCompare(b)) const days = ordered .filter(d => d.id !== dayId) .map((d, i) => ({ ...d, day_number: i + 1, date: dates.length ? (dates[i] ?? null) : d.date })) diff --git a/client/src/utils/dayDeleteImpact.ts b/client/src/utils/dayDeleteImpact.ts index 83a242111..0c5f9e911 100644 --- a/client/src/utils/dayDeleteImpact.ts +++ b/client/src/utils/dayDeleteImpact.ts @@ -180,7 +180,7 @@ export function dayDeleteImpact( const position = new Map(ordered.map((d, i) => [d.id, i])) const at = position.get(day.id) ?? -1 const remaining = ordered.filter(d => d.id !== day.id) - const dates = ordered.map(d => d.date).filter((d): d is string => !!d).sort() + const dates = ordered.map(d => d.date).filter((d): d is string => !!d).sort((a, b) => a.localeCompare(b)) const moved = new Set() let datedSpare: DatedSpare | null = null diff --git a/server/src/nest/days/day-removal.service.ts b/server/src/nest/days/day-removal.service.ts index 2a5fd8205..deef53637 100644 --- a/server/src/nest/days/day-removal.service.ts +++ b/server/src/nest/days/day-removal.service.ts @@ -209,7 +209,7 @@ export class DayRemovalService { */ private renumber(tripId: number, rows: DayRow[], remaining: DayRow[]): string | null { // ISO dates sort as plain strings. - const sortedDates = rows.map(r => r.date).filter((d): d is string => !!d).sort(); + const sortedDates = rows.map(r => r.date).filter((d): d is string => !!d).sort((a, b) => a.localeCompare(b)); const setNumber = this.db.prepare('UPDATE days SET day_number = ? WHERE id = ?'); const setNumberAndDate = this.db.prepare('UPDATE days SET day_number = ?, date = ? WHERE id = ?');