mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 19:30:57 +00:00
add overnight desk handling and effective window configuration for train schedules
This commit is contained in:
@@ -119,6 +119,34 @@ describe('computeImportWindowTimes — first-window open respects office hours',
|
||||
);
|
||||
expect(windowClosesAt.toISOString()).toBe(departure.toISOString());
|
||||
});
|
||||
|
||||
describe('overnight desk (open > close, wraps past midnight)', () => {
|
||||
// Desk open 08:00, closes 05:00 next morning — open across midnight.
|
||||
const overnight = { ...bounded, windowOpenHour: 8, windowCloseHour: 5 };
|
||||
|
||||
it('opens NOW at 00:00 (deep night is INSIDE the overnight window)', () => {
|
||||
// Now = 05 Jul 00:00 EAT (04 Jul 21:00 UTC): after midnight, before 05:00 →
|
||||
// inside the overnight desk → open immediately. This is the reported bug.
|
||||
const now = new Date('2026-07-04T21:00:00.000Z');
|
||||
const { windowOpensAt } = computeImportWindowTimes(departure, overnight, now);
|
||||
expect(windowOpensAt.toISOString()).toBe('2026-07-04T21:00:00.000Z');
|
||||
});
|
||||
|
||||
it('opens NOW at 22:00 (evening is INSIDE the overnight window)', () => {
|
||||
// Now = 05 Jul 22:00 EAT (19:00 UTC): after 08:00 open → inside → open now.
|
||||
const now = new Date('2026-07-05T19:00:00.000Z');
|
||||
const { windowOpensAt } = computeImportWindowTimes(departure, overnight, now);
|
||||
expect(windowOpensAt.toISOString()).toBe('2026-07-05T19:00:00.000Z');
|
||||
});
|
||||
|
||||
it('waits to 08:00 when now is in the daytime gap [05:00, 08:00)', () => {
|
||||
// Now = 05 Jul 06:00 EAT (03:00 UTC): desk shut (gap) → open 08:00 today.
|
||||
const now = new Date('2026-07-05T03:00:00.000Z');
|
||||
const { windowOpensAt } = computeImportWindowTimes(departure, overnight, now);
|
||||
// 05 Jul 08:00 EAT = 05:00 UTC.
|
||||
expect(windowOpensAt.toISOString()).toBe('2026-07-05T05:00:00.000Z');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeImportWindowTimes — overnight desk (open > close, wraps midnight)', () => {
|
||||
|
||||
Reference in New Issue
Block a user