Files
HealthLog/src/lib/time-window-format.ts
T
Marc-André Bombeck 6e49b57a6f 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).
2026-06-07 14:41:15 +02:00

45 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function formatTimeWindowPart(value: string): string {
const m = /^(\d{1,2}):(\d{2})$/.exec(value.trim());
if (!m) return value;
const hh = m[1].padStart(2, "0");
const mm = m[2];
return `${hh}:${mm}`;
}
import type { Locale } from "@/lib/i18n/config";
/**
* Render a daily intake time window like "08:00 bis 12:00 Uhr" / "08:00 – 12:00".
*
* The historic call sites (see `medication-card.tsx`, `medication-form.tsx`)
* never passed a locale, so the renderer hard-coded the German "bis ... Uhr"
* suffix and the English locale ended up with mixed-language strings such as
* `"Today, 19:00 bis 23:00 Uhr"`. Pass the active UI locale so that the right
* separator + suffix are picked. When no locale is provided we keep the
* legacy German output for backwards compatibility with any consumer we may
* have missed.
*
* v1.4.25 W9e — locales other than DE render with the language-neutral
* "08:00 – 12:00" form (the same as EN) until a locale-specific suffix
* ships. The DE branch keeps its trailing "Uhr" suffix verbatim.
*/
export function formatTimeWindowRange(
start: string,
end: string,
locale?: Locale,
): 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`;
}
return `${s} – ${e}`;
}