fix(charts): draw bucket boundaries in the profile's calendar, not Berlin's

The bucketer hard-coded Europe/Berlin for day, week and month boundaries, so
a reading taken on the last evening of a month landed in the wrong month's
bar for everyone who does not live there. Two smaller siblings did the same
thing: the Today chip asked the browser for a time instead of the profile,
and the score card's tooltip formatter carried a locale but no timezone.

The boundary timezone is a required option rather than a defaulted one. A
default would have left any caller that forgets to pass one still wrong and
still silent; required makes the compiler name them, which is how the three
call sites and the eight test sites in this diff were found rather than
guessed at. The tests were always asserting Berlin's calendar without saying
so, and now they say so.

Two fixture mistakes worth recording, both caught by running the tests rather
than trusting them: summer time is already in force in Berlin on 31 March, so
the first instant chosen was April on both sides; and 31 March 2025 falls in
the same ISO week as 1 April, so the week case needed its own instant where
one side is still Sunday.
This commit is contained in:
Marc-André Bombeck committed 2026-07-26 23:18:12 +02:00
1 parent 87877b285f
commit f1773cf602
8 files changed
+183 -51

No files matched your search

@@ -11,6 +11,7 @@ import {
Scale,
} from "lucide-react";
import { useTranslations } from "@/lib/i18n/context";
import { readStoredTimezone } from "@/lib/timezone-mirror";
import { cn } from "@/lib/utils";
import { HealthScoreDeltaExplainer } from "./health-score-delta-explainer";
@@ -219,12 +220,21 @@ export function HealthScoreCard({
// we fall through to the raw ISO so the user still sees something.
// The formatter is memoised per locale so the row map below doesn't
// build a fresh `Intl.DateTimeFormat` instance per row.
// The timezone is as load-bearing as the locale and was missing: without it
// the formatter used the browser's, so a reading taken late in the evening
// could print yesterday's date for someone whose profile timezone is east of
// where their laptop happens to be. The locale still decides the separator
// convention; the timezone decides which day it was.
const asOfFormatter = useMemo(
() =>
new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "short",
day: "2-digit",
// `readStoredTimezone` returns "" when nothing is stored or during
// SSR, and an empty string makes Intl throw RangeError rather than
// fall back. `undefined` is the value that means "use the default".
timeZone: readStoredTimezone() || undefined,
}),
[locale],
);