Files
HealthLog/src/components/measurements/duration-read-as.tsx
T
Marc-André Bombeck 313d8491de feat(measurements): read a sleep duration written as 7:30 or 7h 30m
The sleep field asked for decimal hours only. A shared parser
(parse-duration.ts) now reads a bare number with point or comma,
H:MM, and hours and minutes with unit words (7h, 7h30, 7 h 30 min,
45m), answers in the field's unit, and refuses a negative, unknown or
longer-than-a-day entry. The form shows how the entry was read under
the field and puts a refusal on the field itself. The stored value and
the API are unchanged.

Refs #1101
2026-10-03 18:28:39 +02:00

26 lines
950 B
TypeScript

"use client";
import { useTranslations } from "@/lib/i18n/context";
import { splitDurationMinutes } from "@/lib/measurements/parse-duration";
/**
* How a duration entry was understood, under the field: "Read as 7 h 30 min".
* Shown for every entry the parser accepts, so "7.5", "7:30" and "7h30" can
* each be checked against what the person meant before saving.
*/
export function DurationReadAs({ minutes }: { minutes: number }) {
const { t } = useTranslations();
const parts = splitDurationMinutes(minutes);
const duration =
parts.hours === 0
? t("measurements.durationMinutesOnly", { minutes: parts.minutes })
: parts.minutes === 0
? t("measurements.durationHoursOnly", { hours: parts.hours })
: t("measurements.durationHoursMinutes", parts);
return (
<span aria-live="polite" data-duration-minutes={Math.round(minutes)}>
{t("measurements.durationReadAs", { duration })}
</span>
);
}