Files
HealthLog/src/lib/time-window-format.ts
T
Marc-André BombeckandClaude Opus 4.7 180f46c24e fix(medications): localise time-window range string
`formatTimeWindowRange` used to hard-code the German "bis ... Uhr"
suffix, so an English-locale user saw "Today, 19:00 bis 23:00 Uhr"
on the medication card and the medication form. Pass the active
locale through and emit "19:00 – 23:00" for English while keeping
the existing German output for DE users (and unchanged for legacy
call sites that still don't pass a locale).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 13:29:07 +02:00

32 lines
1.0 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}`;
}
/**
* 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.
*/
export function formatTimeWindowRange(
start: string,
end: string,
locale?: "de" | "en",
): string {
const s = formatTimeWindowPart(start);
const e = formatTimeWindowPart(end);
if (locale === "en") {
return `${s} – ${e}`;
}
return `${s} bis ${e} Uhr`;
}