import { strict as assert } from "node:assert"; import { test } from "node:test"; import dayjs from "dayjs"; import { getServiceMinute, getServiceTimeDifference, normalizeTime, parseClockTime, setClockTime, setServiceTime, } from "../lib/timeUtils"; test("legacy timetable clock values normalize to HH:mm", () => { assert.equal(normalizeTime("4:5"), "04:05"); assert.equal(normalizeTime(" 04:05 "), "04:05"); assert.equal(parseClockTime("24:00"), null); assert.equal(normalizeTime("invalid"), "invalid"); }); test("clock time and service time intentionally differ after midnight", () => { const base = dayjs("2026-09-04T23:50:00"); assert.equal( setClockTime(base, "00:10")?.format("YYYY-MM-DD HH:mm"), "2026-09-04 00:10", ); assert.equal( setServiceTime(base, "00:10")?.format("YYYY-MM-DD HH:mm"), "2026-09-05 00:10", ); }); test("service-time difference handles both sides of midnight", () => { assert.equal( getServiceTimeDifference(dayjs("2026-09-04T23:50:00"), "00:10"), 20, ); assert.equal( getServiceTimeDifference(dayjs("2026-09-05T00:10:00"), "00:30"), 20, ); }); test("service minutes retain the 04:00 railway-day boundary", () => { assert.equal(getServiceMinute("03:59"), 1679); assert.equal(getServiceMinute("04:00"), 240); assert.equal(getServiceMinute("invalid"), null); });