feat(day): fixed-time break such as lunch 12-13 in the day schedule (1.89.15)
This commit is contained in:
1 parent
10a0dd49bd
commit
5b34317bcb
10 files changed
+113
-19
No files matched your search
@@ -11,7 +11,17 @@ export const DEFAULT_CALL_MIN = 10;
|
||||
// gapMin = break between heats of one round; roundGapMin = between rounds (practice -> qualifying,
|
||||
// round 1 -> round 2, final leg 1 -> leg 2); finalsGapMin = before the finals (lunch). Empty
|
||||
// round / finals gaps fall back to the one before. breaks = { sessionId: minutes } of extra
|
||||
// break before that heat. callMin = how long before its start a heat is called.
|
||||
// break before that heat. breakFrom / breakTo = a break at fixed clock times ("12:00"-"13:00",
|
||||
// lunch): no heat starts or runs inside it. callMin = how long before its start a heat is called.
|
||||
const clockTime = (value) => { const match = String(value || "").trim().match(/^(\d{1,2}):(\d{2})$/); return match && Number(match[1]) < 24 && Number(match[2]) < 60 ? `${match[1].padStart(2, "0")}:${match[2]}` : null; };
|
||||
// The fixed-time break of a day as timestamps, or null.
|
||||
export function fixedBreakWindow(day) {
|
||||
const plan = normalizeRaceDay(day || {});
|
||||
if (!plan.breakFrom || !/^\d{4}-\d{2}-\d{2}$/.test(plan.date)) return null;
|
||||
const start = new Date(`${plan.date}T${plan.breakFrom}:00`).getTime();
|
||||
const end = new Date(`${plan.date}T${plan.breakTo}:00`).getTime();
|
||||
return Number.isFinite(start) && Number.isFinite(end) && end > start ? { start, end, from: plan.breakFrom, to: plan.breakTo, label: plan.breakLabel } : null;
|
||||
}
|
||||
const optionalMin = (value) => (value === null || value === undefined || value === "" || !Number.isFinite(Number(value)) ? null : Math.max(0, Number(value)));
|
||||
export function normalizeRaceDay(day = {}) {
|
||||
const breaks = Object.fromEntries(Object.entries(day.breaks && typeof day.breaks === "object" ? day.breaks : {})
|
||||
@@ -23,6 +33,11 @@ export function normalizeRaceDay(day = {}) {
|
||||
roundGapMin: optionalMin(day.roundGapMin),
|
||||
finalsGapMin: optionalMin(day.finalsGapMin),
|
||||
breaks,
|
||||
...(() => {
|
||||
const from = clockTime(day.breakFrom);
|
||||
const to = clockTime(day.breakTo);
|
||||
return from && to && to > from ? { breakFrom: from, breakTo: to, breakLabel: String(day.breakLabel || "").trim().slice(0, 40) } : { breakFrom: null, breakTo: null, breakLabel: "" };
|
||||
})(),
|
||||
callMin: Number(day.callMin) > 0 ? Math.min(60, Number(day.callMin)) : DEFAULT_CALL_MIN,
|
||||
sessionOrder: [...new Set((Array.isArray(day.sessionOrder) ? day.sessionOrder : []).map(String).filter(Boolean))],
|
||||
autopilot: day.autopilot === true,
|
||||
@@ -111,13 +126,16 @@ export function buildDaySchedule(ordered, day, now = Date.now()) {
|
||||
let cursor = Number(day?.startAt || 0) || firstStart || now;
|
||||
let upcomingIndex = 0;
|
||||
let previous = null;
|
||||
const fixed = fixedBreakWindow(day);
|
||||
const overlapsFixed = (start, durationMs) => Boolean(fixed && start < fixed.end && start + durationMs > fixed.start);
|
||||
return ordered.map((session) => {
|
||||
const durationMs = sessionDurationMs(session);
|
||||
const actualStart = Number(session.startedAt || 0) || null;
|
||||
const actualEnd = isDone(session) ? Number(session.endedAt || 0) || null : null;
|
||||
// The first heat starts at the day's start time; an extra break before it still counts.
|
||||
const breakMin = breakBeforeMin(previous, session, day);
|
||||
const planned = cursor + breakMin * 60000;
|
||||
let planned = cursor + breakMin * 60000;
|
||||
let afterFixedBreak = false;
|
||||
previous = session;
|
||||
let state = "upcoming";
|
||||
let start = planned;
|
||||
@@ -132,13 +150,17 @@ export function buildDaySchedule(ordered, day, now = Date.now()) {
|
||||
const pausedMs = Number(session.totalPausedMs || 0) + (session.status === "paused" && session.pausedAt ? Math.max(0, now - Number(session.pausedAt)) : 0);
|
||||
end = Math.max(now, actualStart + durationMs + pausedMs);
|
||||
} else {
|
||||
// A heat that would start or run into the fixed break (lunch) waits until it is over.
|
||||
if (overlapsFixed(planned, durationMs)) { planned = fixed.end; afterFixedBreak = true; }
|
||||
start = Math.max(planned, now);
|
||||
if (overlapsFixed(start, durationMs)) { start = fixed.end; afterFixedBreak = true; }
|
||||
end = start + durationMs;
|
||||
}
|
||||
cursor = end;
|
||||
return {
|
||||
session,
|
||||
breakMin,
|
||||
afterFixedBreak,
|
||||
state,
|
||||
plannedStart: planned,
|
||||
start,
|
||||
|
||||
Reference in new issue
Block a user