mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 12:58:13 +00:00
Add booking window management and locomotive scheduling features
- Implemented migration to release stuck assigned locomotives. - Added schedule window phases to train schedules. - Created booking batch offers table for partial capacity bookings. - Developed BookingSplitService to handle partial booking offers and splits. - Introduced BookingWindowService to manage booking window lifecycle and transitions. - Added BookingBatchOffer entity to represent offers made during booking splits. - Enhanced locomotive options with warnings for scheduling. - Created UpcomingWindowsSection component to display upcoming booking windows.
This commit is contained in:
@@ -121,6 +121,66 @@ function windowFromEatStart(
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a UTC Date for an EAT wall-clock time on a `yyyy-MM-dd` EAT calendar day. */
|
||||
export function eatDayToUtc(day: string, hour: number, minute = 0): Date {
|
||||
const [year, month, dayOfMonth] = day.split('-').map(Number);
|
||||
return eatToUtc(year, month, dayOfMonth, hour, minute);
|
||||
}
|
||||
|
||||
/** Shift a `yyyy-MM-dd` EAT day key by whole days. */
|
||||
export function shiftEatDay(day: string, deltaDays: number): string {
|
||||
// Noon UTC keeps the +3h EAT offset from crossing a day boundary.
|
||||
const [year, month, dayOfMonth] = day.split('-').map(Number);
|
||||
const shifted = new Date(Date.UTC(year, month - 1, dayOfMonth + deltaDays, 12));
|
||||
return `${shifted.getUTCFullYear()}-${String(shifted.getUTCMonth() + 1).padStart(2, '0')}-${String(
|
||||
shifted.getUTCDate(),
|
||||
).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
export interface InitialWindowTimes {
|
||||
windowOpensAt: Date;
|
||||
windowClosesAt: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import booking-day window: opens at `windowOpenHour` EAT on departure-day minus
|
||||
* `importWindowLeadDays`, for `windowDurationHours`. A schedule created after its
|
||||
* computed window has fully passed gets a same-day window starting now instead,
|
||||
* capped at departure.
|
||||
*/
|
||||
export function computeImportWindowTimes(
|
||||
departure: Date,
|
||||
cfg: {
|
||||
importWindowLeadDays: number;
|
||||
windowOpenHour: number;
|
||||
windowDurationHours: number;
|
||||
},
|
||||
now: Date,
|
||||
): InitialWindowTimes {
|
||||
const windowDay = shiftEatDay(eatDay(departure), -cfg.importWindowLeadDays);
|
||||
let opensAt = eatDayToUtc(windowDay, cfg.windowOpenHour);
|
||||
let closesAt = new Date(opensAt.getTime() + cfg.windowDurationHours * 3_600_000);
|
||||
if (closesAt.getTime() <= now.getTime()) {
|
||||
opensAt = now;
|
||||
closesAt = new Date(now.getTime() + cfg.windowDurationHours * 3_600_000);
|
||||
}
|
||||
if (closesAt.getTime() > departure.getTime()) {
|
||||
closesAt = departure;
|
||||
}
|
||||
return { windowOpensAt: opensAt, windowClosesAt: closesAt };
|
||||
}
|
||||
|
||||
/** Export booking window: FCFS from `exportBookingLeadHours` before departure until departure. */
|
||||
export function computeExportWindowTimes(
|
||||
departure: Date,
|
||||
cfg: { exportBookingLeadHours: number },
|
||||
): InitialWindowTimes {
|
||||
return {
|
||||
windowOpensAt: new Date(departure.getTime() - cfg.exportBookingLeadHours * 3_600_000),
|
||||
windowClosesAt: departure,
|
||||
};
|
||||
}
|
||||
|
||||
/** Which 3h EAT intake window a timestamp (e.g. fullyExecutedAt) belongs to. */
|
||||
export function getBatchWindowForTimestamp(date: Date): BatchWindow {
|
||||
const { year, month, day, hour } = eatParts(date);
|
||||
|
||||
Reference in New Issue
Block a user