fix(medications): collapse an equal-bound dose time to a single time

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).
This commit is contained in:
Marc-André Bombeck committed 2026-06-07 14:41:15 +02:00
1 parent 51a7d36366
commit 6e49b57a6f
2 files changed
+27

No files matched your search

@@ -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");
});
});
+7
View File
@@ -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`;
}