fix(planner): close the accommodation loop when no times are recorded

With "optimize route from accommodation" on, the drawn route still started at
the first activity on any arrival day and stopped at the last one on any
departure day. The two bookend rules ask whether you can be proven to have been
at the hotel already — but they read a missing check-in time as proof against,
and the hotel picker leaves that field blank by default. So the loop hung open
at one end on every boundary day, and at both ends for a stay booked on a single
day.

With no time recorded there is no bar to clear, so the leg is drawn. Where a
time *is* set the existing rules are untouched: a stop before check-in still
draws nothing (#1465), and a transport arrival is still not a hotel departure
(#1321).

Closes #2009
This commit is contained in:
Maurice
2026-08-21 12:47:30 +02:00
committed by Maurice
parent 5e78069223
commit 9094f05604
2 changed files with 29 additions and 6 deletions
+18 -4
View File
@@ -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)', () => {
+11 -2
View File
@@ -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 = (