From cb29c5471b9f943248cca8c5018ab813c98e0c94 Mon Sep 17 00:00:00 2001 From: larssand Date: Fri, 13 Nov 2026 09:34:41 +0100 Subject: [PATCH] fix(day): a heat already run between pending ones no longer gives every later heat the same time (1.89.16) --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- src/day_schedule_logic.js | 11 ++++++++--- tests/day_schedule.test.js | 13 +++++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6d02a..834bc0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm No changes recorded yet. +## 1.89.16 - 2026-11-13 + +### Fixed + +- Today's schedule: when classes take turns, a heat already run between heats still waiting no longer pulls the rest of the day back to "now" - upcoming heats got the same start time. They now follow one after the other again, and none is planned before the day's first start. + ## 1.89.15 ### Added diff --git a/package-lock.json b/package-lock.json index b927287..67acdad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.89.15", + "version": "1.89.16", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.89.15", + "version": "1.89.16", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index aefcc3a..d2283df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.89.15", + "version": "1.89.16", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/day_schedule_logic.js b/src/day_schedule_logic.js index 3219e2b..fd1f528 100644 --- a/src/day_schedule_logic.js +++ b/src/day_schedule_logic.js @@ -123,7 +123,8 @@ export function moveInDayOrder(ordered, sessionId, step) { // its first real start, else from now. export function buildDaySchedule(ordered, day, now = Date.now()) { const firstStart = ordered.map((session) => Number(session.startedAt || 0)).filter(Boolean).sort((a, b) => a - b)[0]; - let cursor = Number(day?.startAt || 0) || firstStart || now; + const dayStartAt = Number(day?.startAt || 0) || 0; + let cursor = dayStartAt || firstStart || now; let upcomingIndex = 0; let previous = null; const fixed = fixedBreakWindow(day); @@ -152,11 +153,15 @@ export function buildDaySchedule(ordered, day, now = Date.now()) { } 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); + // Not before the day's first start, nor before now. + start = Math.max(planned, now, dayStartAt); if (overlapsFixed(start, durationMs)) { start = fixed.end; afterFixedBreak = true; } end = start + durationMs; } - cursor = end; + // A heat already run that comes after one still waiting (classes take turns, so a done + // heat of one class can follow a pending one of another) must not pull the cursor back + // to its real, earlier end - every heat after it would then get the same time ("now"). + cursor = upcomingIndex > 0 || state === "upcoming" ? Math.max(cursor, end) : end; return { session, breakMin, diff --git a/tests/day_schedule.test.js b/tests/day_schedule.test.js index 72165cc..1b215e1 100644 --- a/tests/day_schedule.test.js +++ b/tests/day_schedule.test.js @@ -157,3 +157,16 @@ test("the drivers' board shows the lunch while it is on, and before the heat aft const before = renderDriverBoard({ t: (k) => k, escapeHtml: String, date: "2026-11-08", rows, getClassLabel: () => "2WD", getSessionGridEntries: () => [], getRemainingLabel: () => "", day, now: at("11:58") }); assert.doesNotMatch(before, /class="board-live board-break"/, "no lunch banner before lunch"); }); + +test("a heat already run between pending ones doesn't pull the rest of the day back to now", () => { + const T = (h) => new Date(`2026-11-12T${h}:00`).getTime(); + const sessions = [ + { id: "p", type: "practice", name: "practice 1", status: "ready", durationMin: 5 }, + { id: "x", type: "practice", name: "other", status: "finished", durationMin: 5, startedAt: T("19:00"), endedAt: T("19:05") }, + { id: "q1", type: "qualification", name: "Q1 H1", status: "ready", durationMin: 5 }, + { id: "y", type: "qualification", name: "other q", status: "finished", durationMin: 5, startedAt: T("19:30"), endedAt: T("19:35") }, + { id: "q2", type: "qualification", name: "Q2 H1", status: "ready", durationMin: 5 }, + ]; + const rows = buildDaySchedule(sessions, { startAt: T("23:40"), gapMin: 3 }, T("23:39")).filter((row) => row.state === "upcoming"); + assert.deepEqual(rows.map((row) => row.start), [T("23:40"), T("23:48"), T("23:56")], "one after the other from the first start, not all at 23:39"); +});