Files
HealthLog/src/lib/time-window-format.ts
T
Marc-André Bombeck fea1d1e0b5 chore: strip planning tags from comments and enable the rule
Output of `node scripts/strip-planning-tags.mjs --write`: 3,157 comment
lines in 1,308 files lose the work-item identifier at their head. Release
versions and issue references stay; nothing outside comment text
changes, which the script checks per file against a comment-free
printout. healthlog/no-planning-tags is enabled at error level with this
commit, so the tree it lands on is clean.
2026-10-20 09:08:40 +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 — 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}`;
}