mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 14:06:27 +00:00
154c88b48a
A visit's End could be edited and was shown in road trip mode, but the schedule never read it: the drive always left a stop after its stay, so a traveller who knew when they had to leave but not how long they would stand there had no way to say so. The End is now the time the drive leaves. RoadtripStop.leaveAt is filled from the visit's End (or its place's) on the client by useRoadtripRoutes and on the server by roadtrip-plan.service, so calculate_roadtrip and get_roadtrip_context agree with the planner, and computeSchedule takes it as the departure it already knew how to hold. With Start and End both set the stay is the time between them. With daily travel times on, the stay is the time until then, and an End before the window start starts the day early the way a Start does. Before the first fixed time the chain works backwards through an End as it does through a pinned Start. An End is read against the drive: the last passing of that clock time counts as missed when the drive went past it on the road or earlier the same day, anything else is the next one, so a drive across midnight neither waits a whole day nor pretends to be on time. A drive that gets there after the End leaves on arrival and files a missedLeave finding, shown beside the late badge in the rail and on the phone. The rail's STAY badge, the inspector's Stay tile, the phone stop sheet and the phone chain show the stay the End makes, with an "until 14:00" hint. It is read off the schedule and never written to duration_minutes: the stay belongs to the place, the End to one visit, and a stored copy would go stale as soon as the arrival moved. For such a stop the stay dialog, desktop and phone, shows that stay read only and offers to remove the End, through the visit's time route with an offline path (assignmentRepo.setTimes, setAssignmentTimes). While the road trip is on, the End field in both place forms says the drive leaves at that time. The dead checkoutAt in the plan service is gone. New strings in all 23 locales.
63 lines
3.3 KiB
TypeScript
63 lines
3.3 KiB
TypeScript
import { continueSchedule } from './continueSchedule';
|
|
import type { RoadtripStop } from './planning-types';
|
|
import type { Schedule } from './roadtripModel';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const stops = [0, 60, 60, 60].map((dwellMinutes) => ({ dwellMinutes }) as RoadtripStop);
|
|
const schedule = (): Schedule => ({
|
|
entries: [
|
|
{ arrival: '18:15', departure: '18:15', dayOffset: 0, anchored: false },
|
|
...[1, 2, 3].map(() => ({ arrival: null, departure: null, dayOffset: 0, anchored: false })),
|
|
],
|
|
warnings: [],
|
|
});
|
|
describe('continuing after a moved day group', () => {
|
|
it('carries Munich departure into the original day stops and over midnight', () => {
|
|
const original = schedule();
|
|
const completed = continueSchedule(stops, original, [237 * 60, 198 * 60, 206 * 60], 2);
|
|
expect(completed.entries.map((entry) => entry.arrival)).toEqual(['18:15', '22:12', '02:30', '06:56']);
|
|
expect(completed.entries[2]!.dayOffset).toBe(1);
|
|
expect(original.entries[1]!.arrival).toBeNull();
|
|
});
|
|
it('keeps manual times and stops at an unknown route duration', () => {
|
|
const original = schedule();
|
|
original.entries[2] = { arrival: '07:00', departure: '08:00', dayOffset: 1, anchored: true };
|
|
const completed = continueSchedule(stops, original, [undefined, 3600, 3600], 2);
|
|
expect(completed.entries[1]!.arrival).toBeNull();
|
|
expect(completed.entries[2]).toEqual(original.entries[2]);
|
|
expect(completed.entries[3]!.arrival).toBe('09:00');
|
|
});
|
|
it('holds a stop with a leave time until then, and reports one it reaches too late', () => {
|
|
const leaving = [
|
|
{ dwellMinutes: 0 },
|
|
{ dwellMinutes: 60, leaveAt: '23:30' },
|
|
{ dwellMinutes: 60, leaveAt: '00:30' },
|
|
{ dwellMinutes: 0 },
|
|
] as RoadtripStop[];
|
|
const completed = continueSchedule(leaving, schedule(), [3600, 3600, 3600], 2);
|
|
// In at 19:15 and out at 23:30, not at 20:15.
|
|
expect(completed.entries[1]).toMatchObject({ arrival: '19:15', departure: '23:30' });
|
|
// Reached on the minute it is meant to be left at: gone at once, and not late.
|
|
expect(completed.entries[2]).toMatchObject({ arrival: '00:30', departure: '00:30', dayOffset: 1 });
|
|
expect(completed.entries[3]!.arrival).toBe('01:30');
|
|
expect(completed.warnings).not.toContainEqual(expect.objectContaining({ code: 'missedLeave' }));
|
|
// Another hour on the road and it is reached an hour after it should have been left.
|
|
const late = continueSchedule(leaving, schedule(), [3600, 7200, 3600], 2);
|
|
expect(late.warnings).toContainEqual({ index: 2, code: 'missedLeave', minutes: 60 });
|
|
});
|
|
it('reports a leave time the drive went past before midnight rather than waiting for the next one', () => {
|
|
const leaving = [
|
|
{ dwellMinutes: 0 },
|
|
{ dwellMinutes: 60, leaveAt: '23:30' },
|
|
{ dwellMinutes: 60 },
|
|
{ dwellMinutes: 0 },
|
|
] as RoadtripStop[];
|
|
// Out of Munich at 18:15, six and a quarter hours to go: in at half past midnight.
|
|
const completed = continueSchedule(leaving, schedule(), [375 * 60, 3600, 3600], 2);
|
|
expect(completed.entries[1]).toMatchObject({ arrival: '00:30', departure: '00:30', dayOffset: 1 });
|
|
expect(completed.entries[2]!.arrival).toBe('01:30');
|
|
expect(completed.warnings).toContainEqual({ index: 1, code: 'missedLeave', minutes: 60 });
|
|
});
|
|
});
|