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.
This commit is contained in:
Maurice
2026-09-23 23:11:10 +02:00
parent 954758082b
commit c5ac479915
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ type DayState = Pick<TripStoreState, 'days' | 'assignments' | 'dayNotes' | 'sele
*/ */
export function withoutDay(state: DayState, dayId: number): DayState { export function withoutDay(state: DayState, dayId: number): DayState {
const ordered = [...state.days].sort((a, b) => (a.day_number ?? 0) - (b.day_number ?? 0)) const ordered = [...state.days].sort((a, b) => (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 const days = ordered
.filter(d => d.id !== dayId) .filter(d => d.id !== dayId)
.map((d, i) => ({ ...d, day_number: i + 1, date: dates.length ? (dates[i] ?? null) : d.date })) .map((d, i) => ({ ...d, day_number: i + 1, date: dates.length ? (dates[i] ?? null) : d.date }))
+1 -1
View File
@@ -180,7 +180,7 @@ export function dayDeleteImpact(
const position = new Map(ordered.map((d, i) => [d.id, i])) const position = new Map(ordered.map((d, i) => [d.id, i]))
const at = position.get(day.id) ?? -1 const at = position.get(day.id) ?? -1
const remaining = ordered.filter(d => d.id !== day.id) 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<number>() const moved = new Set<number>()
let datedSpare: DatedSpare | null = null let datedSpare: DatedSpare | null = null
+1 -1
View File
@@ -209,7 +209,7 @@ export class DayRemovalService {
*/ */
private renumber(tripId: number, rows: DayRow[], remaining: DayRow[]): string | null { private renumber(tripId: number, rows: DayRow[], remaining: DayRow[]): string | null {
// ISO dates sort as plain strings. // 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 setNumber = this.db.prepare('UPDATE days SET day_number = ? WHERE id = ?');
const setNumberAndDate = this.db.prepare('UPDATE days SET day_number = ?, date = ? WHERE id = ?'); const setNumberAndDate = this.db.prepare('UPDATE days SET day_number = ?, date = ? WHERE id = ?');