From ff676c8fc205aedda206e4414326fa03a7a481a0 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 28 Nov 2026 00:33:07 +0100 Subject: [PATCH] fix(bookings): move hotels and day-linked transports into Past once their days are over A booking without a date of its own now reads its stay or linked day for that, as the date sort already does, so the Past section also opens once the whole trip is over. --- .../Planner/bookings/bookingsModel.test.ts | 17 +++++++++++++++++ .../Planner/bookings/bookingsModel.ts | 16 ++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) 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')