fix(roadtrip): a hotel visited again on its check-in day is the night only at its last visit

A stop counted as the booked night whenever a stay began at its place on its
day, so a hotel on its check-in day twice (the booking's own stop and a rest
the traveller planned there) was read as two nights. Both were held to the
check-in: the rest waited for the room or was set back to it, and with a check-in
far from its arrival the rest and every stop behind it moved onto the next day's
card.

oneNightPerStay in shared keeps the night and its check-in on the last visit of
the place and turns the earlier ones into ordinary stops, still a hotel. The
browser and calculate_roadtrip both run it, the stored ride slot times only that
row by the check-in, and opening an earlier visit in road trip mode opens the
stop rather than the night.

Refs #2636
This commit is contained in:
Maurice
2026-10-12 11:05:41 +02:00
parent e3bf18f9a6
commit 565333a90c
12 changed files with 229 additions and 33 deletions
+9
View File
@@ -413,6 +413,15 @@ describe('storedRideSlot', () => {
expect(storedRideSlot(ferry(), [amsterdam, hotel], [{ ...checkIn[0], start_day_id: 4 }], 5)).toBe(0.5)
})
it('times only the last visit of the hotel by its check-in, an earlier one is a stop (#2636)', () => {
// Checked in at six, after the 17:30 sailing: the night is behind the crossing, and so
// is the rest at the same hotel before it. Read as a second check-in it timed the rest
// at six too, and the slot went behind both, so the drive reached them overland.
const checkIn = [{ place_id: 30, start_day_id: 5, check_in: '18:00' }]
const night = { ...hotel, id: 4, order_index: 2 }
expect(storedRideSlot(ferry(), [amsterdam, hotel, night], checkIn, 5)).toBe(0.5)
})
it('opens the day, closes it, or sits behind a timed row, measured on order indexes', () => {
expect(storedRideSlot(ferry(), [row(2, 3, 54.9783, -1.6178)], [], 5)).toBe(2.5)
expect(storedRideSlot(ferry(), [amsterdam], [], 5)).toBe(0.5)
+9 -3
View File
@@ -375,8 +375,9 @@ interface StoredStop {
* number among their order indexes all the same, and worked out over the rows the list
* shows it could land behind a hidden stop on the far shore, which the drive then went to
* overland before the crossing (#2461). Each row counts with its start, else the check-in
* of the stay that begins there that day (`stayStartingOn`), and with its coordinates; a
* row without them is no stop of the drive. Where the rule keeps the clock's seat, the
* of the stay that begins there that day (`stayStartingOn`) on the place's last row of the
* day, and with its coordinates; a row without them is no stop of the drive. Where the
* rule keeps the clock's seat, the
* clock is read over the same rows: behind the last one timed at or before the departure,
* else at the end of the day.
*/
@@ -388,11 +389,16 @@ export function storedRideSlot(
): number | null {
const ride = sameDayRide(r)
if (!ride || !day.length) return null
// The night is the last visit of its hotel on the day (`oneNightPerStay`), so only that
// row is timed by the check-in; an earlier visit of the same place is a stop like any other.
const lastOfPlace = new Map<number | null | undefined, number>()
for (const row of day) lastOfPlace.set(row.place_id, Math.max(lastOfPlace.get(row.place_id) ?? -Infinity, row.order_index))
const items: SeatItem[] = day.flatMap(row => {
const lat = row.place?.lat
const lng = row.place?.lng
if (typeof lat !== 'number' || typeof lng !== 'number' || !Number.isFinite(lat) || !Number.isFinite(lng)) return []
const start = row.place?.place_time ?? stayStartingOn(stays, row.place_id, dayId)?.check_in
const night = lastOfPlace.get(row.place_id) === row.order_index
const start = row.place?.place_time ?? (night ? stayStartingOn(stays, row.place_id, dayId)?.check_in : null)
return [{ key: row.order_index, minutes: parseTimeToMinutes(start), point: { lat, lng } }]
})
const keys = day.map(row => row.order_index)