From 6e49b57a6fd6d93c59dd25e36c71c0c0740cd16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 7 Jun 2026 14:41:15 +0200 Subject: [PATCH] fix(medications): collapse an equal-bound dose time to a single time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A next-dose / status line whose window start equals its end rendered a degenerate range — "07:00 bis 07:00 Uhr" (DE) / "07:00 – 07:00" (EN) — for a single target time or a zero-span window. Reserve the "bis" / "–" separator for a genuine range and render one time when start == end (the DE branch keeps its "Uhr" suffix on the single time). --- src/lib/__tests__/time-window-format.test.ts | 20 ++++++++++++++++++++ src/lib/time-window-format.ts | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/__tests__/time-window-format.test.ts b/src/lib/__tests__/time-window-format.test.ts index c5cf6dd07..030ae70c1 100644 --- a/src/lib/__tests__/time-window-format.test.ts +++ b/src/lib/__tests__/time-window-format.test.ts @@ -37,4 +37,24 @@ describe("formatTimeWindowRange", () => { // continue to render the historic German string. expect(formatTimeWindowRange("08:00", "12:00")).toBe("08:00 bis 12:00 Uhr"); }); + + test("collapses an equal start/end to a single time (German keeps 'Uhr')", () => { + // BUG 1: a single target time (or a zero-span window) must not render the + // degenerate "07:00 bis 07:00 Uhr" range — the "bis" separator is reserved + // for a genuine range. + expect(formatTimeWindowRange("07:00", "07:00", "de")).toBe("07:00 Uhr"); + }); + + test("collapses an equal start/end to a single time (English, no 'to')", () => { + expect(formatTimeWindowRange("07:00", "07:00", "en")).toBe("07:00"); + }); + + test("collapses an equal start/end after zero-padding normalisation", () => { + // "7:00" and "07:00" are the same clock time once normalised. + expect(formatTimeWindowRange("7:00", "07:00", "de")).toBe("07:00 Uhr"); + }); + + test("collapses an equal start/end with no locale (German fallback)", () => { + expect(formatTimeWindowRange("07:00", "07:00")).toBe("07:00 Uhr"); + }); }); diff --git a/src/lib/time-window-format.ts b/src/lib/time-window-format.ts index 37fc9ae8c..747352af5 100644 --- a/src/lib/time-window-format.ts +++ b/src/lib/time-window-format.ts @@ -30,6 +30,13 @@ export function formatTimeWindowRange( ): string { const s = formatTimeWindowPart(start); const e = formatTimeWindowPart(end); + // A degenerate window — start == end (a single target time, or a med with + // no real window span) — must read as ONE time, not "07:00 bis 07:00 Uhr" / + // "07:00 – 07:00". The "bis" / "–" separator is reserved for a genuine + // range. The DE branch keeps its "Uhr" suffix on the single time. + if (s === e) { + return locale === undefined || locale === "de" ? `${s} Uhr` : s; + } if (locale === undefined || locale === "de") { return `${s} bis ${e} Uhr`; }