fix(dates): show a stated calendar date as that date east of UTC+12

Day keys anchored at noon UTC went through the zone-aware
dateShortSmart, which shows them as the next day in UTC+12..+14. A
dateShortSmartCalendar formatter reads the key in UTC with the same
year rule, and the predictions panel, the illness timeline, the
intraday pulse day label, the nutrient chart and the coach result
chart use it. The lab chart dates a date-only reading by its calendar
date and a timed one in the reader's zone, as the lab lists do. The
timezone formatter guard now fails on a noon anchor handed to a
zone-aware formatter.
This commit is contained in:
Marc-André Bombeck committed 2026-10-03 18:44:06 +02:00
1 parent 358ef23239
commit 9ecdda6358
9 files changed
+171 -17

No files matched your search

+13 -3
View File
@@ -18,6 +18,7 @@ import { CHART_HEIGHT_PX } from "@/lib/charts/constants";
import { prefersReducedMotion } from "@/lib/charts/reduced-motion";
import { formatReferenceRange } from "@/lib/labs/reference-range";
import { useTranslations, useFormatters } from "@/lib/i18n/context";
import { isNoonUtcAnchor } from "@/lib/tz/date-only";
import { RichChartTooltip, type RichTooltipRow } from "../charts/chart-tooltip";
import type { LabResultDto } from "./types";
@@ -93,6 +94,15 @@ export function LabBiomarkerChart({
const { t } = useTranslations();
const labNumber = useLabNumber();
const fmt = useFormatters();
// A reading from a report that states only its date is stored at noon UTC
// and is dated by that calendar date; one typed with its time of day is
// dated in the reader's zone (the rule `useLabDate` applies to the lists).
const labShortDate = (value: number | string) => {
const instant = new Date(value);
return isNoonUtcAnchor(instant)
? fmt.dateShortSmartCalendar(instant)
: fmt.dateShortSmart(instant);
};
const [range, setRange] = useState<RangeKey>("365");
// Capture "now" once at mount so the recency filter stays pure across
// re-renders (an inline `Date.now()` in render is impure).
@@ -215,7 +225,7 @@ export function LabBiomarkerChart({
type="number"
scale="time"
domain={["dataMin", "dataMax"]}
tickFormatter={(ts: number) => fmt.dateShortSmart(new Date(ts))}
tickFormatter={(ts: number) => labShortDate(ts)}
tick={{ fontSize: 11, fill: "var(--muted-foreground)" }}
stroke="var(--border)"
minTickGap={32}
@@ -326,7 +336,7 @@ export function LabBiomarkerChart({
return (
<RichChartTooltip
active
label={fmt.dateShortSmart(new Date(point.timestamp))}
label={labShortDate(point.timestamp)}
rows={rows}
/>
);
@@ -348,7 +358,7 @@ export function LabBiomarkerChart({
{sourceBand.mixed
? t("labs.chart.sourceBandMixed")
: t("labs.chart.sourceBandLegend", {
date: fmt.dateShortSmart(new Date(sourceBand.takenAt)),
date: labShortDate(sourceBand.takenAt),
})}
</p>
) : null}