mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
`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>
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
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`;
|
||
}
|