Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(dayplan): sort the trip's dates with an explicit compare

Mauricec5ac47991549
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<TripStoreState, 'days' | 'assignments' | 'dayNotes' | 'sele
*/
export function withoutDay(state: DayState, dayId: number): DayState {
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
.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<number>()
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 = ?');