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(planner): close the accommodation loop when no times are recorded

Maurice9094f0560437
diff --git a/client/src/utils/dayOrder.test.ts b/client/src/utils/dayOrder.test.ts
index 082f44c9b..4d1cd416c 100644
--- a/client/src/utils/dayOrder.test.ts
+++ b/client/src/utils/dayOrder.test.ts
@@ -178,13 +178,21 @@ describe('shouldDrawMorningLeg', () => {
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: '15:00' })).toBe(true)
})
- it('does NOT draw on a check-in day when time info is missing (#1597)', () => {
+ it('does NOT draw on a check-in day when the stop is untimed but check-in is not (#1597)', () => {
// An un-timed first place on an arrival day ("Home" before driving out) cannot prove
// you were at the hotel yet, so no hotel → first-stop leg — mirroring the evening rule.
const bookends = { morning: into({ check_in: '15:00' }), morningIsSleptHere: false }
expect(shouldDrawMorningLeg(bookends, checkInDay, { isPlace: true, time: null })).toBe(false)
+ })
+
+ it('DOES draw on a check-in day when the stay records no check-in time (#2009)', () => {
+ // Nothing to clear, so nothing to fail: the hotel picker leaves the time blank
+ // by default, and treating that as proof against left the loop open every time.
const noCheckIn = { morning: into({ check_in: null }), morningIsSleptHere: false }
- expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: '19:00' })).toBe(false)
+ expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: '19:00' })).toBe(true)
+ expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: true, time: null })).toBe(true)
+ // A transport arrival is still not a hotel departure (#1321).
+ expect(shouldDrawMorningLeg(noCheckIn, checkInDay, { isPlace: false, time: '19:00' })).toBe(false)
})
it('does NOT draw on a check-in day for a transport arrival (not a place, #1321)', () => {
@@ -222,11 +230,17 @@ describe('shouldDrawEveningLeg', () => {
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: true, time: '11:00' })).toBe(true)
})
- it('does NOT draw on a check-out day when the place or hotel has no time', () => {
+ it('does NOT draw on a check-out day when the stop is untimed but check-out is not', () => {
const bookends = { evening: out({ check_out: '11:00' }), eveningIsOvernight: false }
expect(shouldDrawEveningLeg(bookends, checkOutDay, { isPlace: true, time: null })).toBe(false)
+ })
+
+ it('DOES draw on a check-out day when the stay records no check-out time (#2009)', () => {
const noCheckOut = { evening: out({ check_out: null }), eveningIsOvernight: false }
- expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: '09:00' })).toBe(false)
+ expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: '09:00' })).toBe(true)
+ expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: true, time: null })).toBe(true)
+ // An evening transport departure is still not a drive back to the hotel (S7).
+ expect(shouldDrawEveningLeg(noCheckOut, checkOutDay, { isPlace: false, time: '09:00' })).toBe(false)
})
it('does NOT draw on a check-out day for a transport departure (not a place, S7)', () => {
diff --git a/client/src/utils/dayOrder.ts b/client/src/utils/dayOrder.ts
index cf2ce304b..9ebe6cf84 100644
--- a/client/src/utils/dayOrder.ts
+++ b/client/src/utils/dayOrder.ts
@@ -73,8 +73,14 @@ export const shouldDrawMorningLeg = (
const m = bookends.morning
if (!m || m.start_day_id !== day.id || !firstStop?.isPlace) return false
const checkIn = parseTimeToMinutes(m.check_in)
+ // No check-in time on the stay means there is no bar to clear, and "no
+ // information" was being read as "proof against" — which silently opened the
+ // loop at the start of every arrival day, since the hotel picker leaves the
+ // time blank by default (#2009). With a time set, #1465 still holds: an
+ // earlier stop is a place you reached before the hotel and draws no leg.
+ if (checkIn == null) return true
const stop = parseTimeToMinutes(firstStop.time)
- return checkIn != null && stop != null && stop >= checkIn
+ return stop != null && stop >= checkIn
}
// Mirror of shouldDrawMorningLeg for the last-stop → hotel evening leg. It is a real drive when
@@ -91,8 +97,11 @@ export const shouldDrawEveningLeg = (
const e = bookends.evening
if (!e || e.end_day_id !== day.id || !lastStop?.isPlace) return false
const checkOut = parseTimeToMinutes(e.check_out)
+ // Mirror of the morning rule: with no check-out time recorded there is nothing
+ // to have missed, so the return leg is drawn and the loop closes (#2009).
+ if (checkOut == null) return true
const stop = parseTimeToMinutes(lastStop.time)
- return checkOut != null && stop != null && stop <= checkOut
+ return stop != null && stop <= checkOut
}
export const isDayInAccommodationRange = (