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(bookings): move hotels and day-linked transports into Past once their days are over

Mauriceff676c8fc205
diff --git a/client/src/components/Planner/bookings/bookingsModel.test.ts b/client/src/components/Planner/bookings/bookingsModel.test.ts
index a41d1674c..b92550f6a 100644
--- a/client/src/components/Planner/bookings/bookingsModel.test.ts
+++ b/client/src/components/Planner/bookings/bookingsModel.test.ts
@@ -422,4 +422,21 @@ describe('onTravelers and the shared type colours', () => {
expect(groups.past.map(r => r.id)).toEqual([2, 1]);
expect(groupTransports([ahead, early, lastNight], days).past).toEqual([]);
});
+
+ it('FE-PLANNER-BKMODEL-046: hasPassed takes the linked days when a booking carries no date of its own', () => {
+ const now = new Date(2025, 5, 3, 12, 0);
+ const hotel = buildReservation({ id: 1, type: 'hotel', status: 'confirmed', reservation_time: null, reservation_end_time: null, accommodation_start_day_id: 501, accommodation_end_day_id: 502 });
+ const stillThere = buildReservation({ id: 2, type: 'hotel', status: 'confirmed', reservation_time: null, reservation_end_time: null, accommodation_start_day_id: 502, accommodation_end_day_id: 503 });
+ const train = buildReservation({ id: 3, type: 'train', status: 'confirmed', reservation_time: '09:00', reservation_end_time: '11:00', day_id: 503 });
+ const lateTrain = buildReservation({ id: 4, type: 'train', status: 'confirmed', reservation_time: '13:00', day_id: 503 });
+ const overnight = buildReservation({ id: 5, type: 'bus', status: 'confirmed', reservation_time: '22:00', reservation_end_time: '06:00', day_id: 502, end_day_id: 503 });
+ expect(hasPassed(hotel, now, days)).toBe(true);
+ expect(hasPassed(stillThere, now, days)).toBe(false);
+ expect(hasPassed(train, now, days)).toBe(true);
+ expect(hasPassed(lateTrain, now, days)).toBe(false);
+ expect(hasPassed(overnight, now, days)).toBe(true);
+ const groups = groupTransports([hotel, stillThere, train, lateTrain, overnight], days, now);
+ expect(groups.past.map(r => r.id)).toEqual([3, 5, 1]);
+ expect(groups.confirmed.map(r => r.id)).toEqual([2, 4]);
+ });
});
diff --git a/client/src/components/Planner/bookings/bookingsModel.ts b/client/src/components/Planner/bookings/bookingsModel.ts
index 7c6999a7b..f370efe9e 100644
--- a/client/src/components/Planner/bookings/bookingsModel.ts
+++ b/client/src/components/Planner/bookings/bookingsModel.ts
@@ -260,15 +260,19 @@ export interface StatusGroups {
* Whether a booking is over: its end, or its start where it has none, lies
* before `now`. The times are local wall-clock values, as everywhere a booking
* is read. An end time without a date is on the start's day, and a date
- * without a time counts until that day is over. A booking without any date
- * (one only placed on a day) is never treated as over.
+ * without a time counts until that day is over. A booking that carries no date
+ * of its own takes them from bookingDates, so a hotel ends on its stay's last
+ * day and a day-linked transport on its day. Without any date it is never over.
*/
-export function hasPassed(r: Reservation, now: Date): boolean {
+export function hasPassed(r: Reservation, now: Date, days: Day[] = []): boolean {
const start = splitReservationDateTime(r.reservation_time)
const end = r.reservation_end_time ? splitReservationDateTime(r.reservation_end_time) : null
- const date = end?.date ?? start.date
+ const own = end?.date || start.date
+ const linked = own ? null : bookingDates(r, days)
+ const endDate = own ? end?.date : linked?.end
+ const date = endDate || (own ? start.date : linked?.start)
if (!date) return false
- const time = end && (end.date || end.time) ? end.time : start.time
+ const time = endDate || end?.time ? (end?.time ?? null) : start.time
const [y, m, d] = date.split('-').map(Number)
const [hh, mm] = time ? time.split(':').map(Number) : [23, 59]
return new Date(y, m - 1, d, hh, mm) < now
@@ -282,7 +286,7 @@ export function hasPassed(r: Reservation, now: Date): boolean {
*/
export function groupTransports(list: Reservation[], days: Day[], now?: Date): StatusGroups {
const sorted = sortReservations(list, days, 'date', 'asc', () => '')
- const isPast = (r: Reservation) => !!now && hasPassed(r, now)
+ const isPast = (r: Reservation) => !!now && hasPassed(r, now, days)
const current = sorted.filter(r => !isPast(r))
const transit = current.filter(r => r.type === 'transit')
const nonTransit = current.filter(r => r.type !== 'transit')