fix(roadtrip): a hire car picked up after a night sets off from the stay (#2993)

With hotel bookends on, a day whose first stop was a hire car pick-up got no morning
bookend, so the drive from the stay to the desk was missing. Only a landing means the
traveller was not at the hotel; the pick-up is the first drive of the day.
This commit is contained in:
Maurice
2026-11-13 09:16:38 +01:00
parent c7cfa5a64f
commit e7bff6681e
3 changed files with 30 additions and 14 deletions
+24 -10
View File
@@ -232,16 +232,30 @@ describe('a transfer day', () => {
describe('a day that starts or ends on a ride or at a hire car desk', () => {
const hotel = stay(5, D1, D4, HOTEL);
// Landing, or at the desk the car is picked up at: the traveller was not at the hotel.
it.each([{ role: 'arrival' }, { role: 'pickup' }] as const)(
'ROADTRIP-BOOKENDS-010: no morning when $role opens the day',
({ role }) => {
const [day] = seatNightBookends([planDay(D2, [terminal(D2, 0, role), visit(D2, 0, { name: 'P' })])], days, [
hotel,
]);
expect(shape(day)).toEqual([role, 'P', 'evening:5']);
},
);
// Landing: the traveller was not at the hotel.
it('ROADTRIP-BOOKENDS-010: no morning when an arrival opens the day', () => {
const [day] = seatNightBookends([planDay(D2, [terminal(D2, 0, 'arrival'), visit(D2, 0, { name: 'P' })])], days, [
hotel,
]);
expect(shape(day)).toEqual(['arrival', 'P', 'evening:5']);
});
// The desk the car is picked up at is where the first drive goes, from the hotel.
it('ROADTRIP-BOOKENDS-039: a hire car picked up after a night sets off from the hotel (#2993)', () => {
const [day] = seatNightBookends([planDay(D2, [terminal(D2, 0, 'pickup'), visit(D2, 0, { name: 'P' })])], days, [
hotel,
]);
expect(shape(day)).toEqual(['morning:5', 'pickup', 'P', 'evening:5']);
});
it('ROADTRIP-BOOKENDS-040: on a check-out day, the pick-up comes after the stay checked out of (#2993)', () => {
const left = stay(1, D1, D2, GETAWAY);
const next = stay(2, D2, D3, WALLINGA);
// The desk a short drive from the hotel checked out of, like the airport of the report.
const desk = { ...terminal(D2, 0, 'pickup'), lat: GETAWAY[0] + 0.1, lng: GETAWAY[1] + 0.1 };
const [day] = seatNightBookends([planDay(D2, [desk, visit(D2, 0, { name: 'P' })])], days, [left, next]);
expect(shape(day)).toEqual(['morning:1', 'pickup', 'P', 'evening:2']);
});
// At the gate, or where the car goes back: the traveller is not driving to the hotel.
it.each([{ role: 'departure' }, { role: 'return' }] as const)(
+5 -3
View File
@@ -5,7 +5,7 @@ import {
isDayInAccommodationRange,
type DayRef,
} from '../day/stay-bookends';
import { closesTheDay, isCarrierType, opensTheDay, type CarrierBooking } from './carriers';
import { closesTheDay, isCarrierType, type CarrierBooking } from './carriers';
import { withinDriveRange } from './corridor';
import { stationary } from './dayWindow';
import type { BookendPhase, PlanDay, RoadtripStop, RoutedLeg } from './planning-types';
@@ -229,7 +229,9 @@ const withinReach = (hotel: BookendStay, stop: RoadtripStop | undefined): boolea
* hold them in any order, and the server choose the same one where two overlap.
*
* The morning gets the stay slept in, unless the day already starts there, or starts on
* landing or at a hire car's desk, where the traveller was not at the hotel. The evening
* landing, where the traveller was not at the hotel. A day that starts at a hire car's
* desk still sets off from the hotel: the traveller checked out and drove or rode to the
* desk, and that is the first drive of the day (#2993). The evening
* gets tonight's stay, unless the day already ends there, or ends at a departure or at the
* desk the hire car goes back to. A day without a stop of its own gets both or neither: a
* morning at one hotel and an evening at another is the drive between them, while a day
@@ -276,7 +278,7 @@ export function seatNightBookends(
const head =
!!hotels.morning &&
!!hotels.morningIsSleptHere &&
!(first && (hotelIsTheStop(hotels.morning, first) || opensTheDay(first.carrier?.role))) &&
!(first && (hotelIsTheStop(hotels.morning, first) || first.carrier?.role === 'arrival')) &&
withinReach(hotels.morning, first);
const tail =
!!hotels.evening &&