chore(release): v1.28.35 — timestamps honor the profile timezone

Client-rendered times fell back to the hardcoded display zone
(Europe/Berlin) because neither useFormatters() nor the legacy format.ts
helpers ever received users.timezone. A third localStorage mirror
(timezone-mirror.ts, following the time-format/date-format pattern)
carries the validated profile zone from /api/auth/me into both read
paths; the fallback chain is strictly profile → Europe/Berlin — never
the browser zone, so screen, PDF, and export cannot disagree.
makeFormatters validates its zone before Intl (a poison value falls back
instead of throwing inside every render).

Same pass, per the two-document audit: formatUpdatedLabel boundary and
clock now resolve one zone in every state (the undefined-tz browser hole
is closed); @db.Date calendar fields render UTC-pinned so profiles west
of UTC cannot shift a day; dose-history day headings and GLP-1 weekday
labels derive from the display zone; chart day/month labels are
encoding-derived and UTC-pinned (bucket math untouched, byte-identical
for Berlin profiles); the clinician share view renders in the patient's
timezone instead of the container's; Playwright pins Europe/Berlin.
Server day-key semantics, streak anchoring, insight cache keys, and
verbatim wall-clock strings are untouched by construction and pinned by
the new Auckland/New_York/Manila + DST test matrix.
This commit is contained in:
Marc-André Bombeck committed 2026-07-14 20:19:23 +02:00
1 parent 136653e3d7
commit 9bbd8a89dc
41 files changed
+958 -90

No files matched your search

@@ -77,7 +77,12 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { useAuth } from "@/hooks/use-auth";
import { useTranslations, useFormatters } from "@/lib/i18n/context";
import {
useTranslations,
useFormatters,
useDateFormatPreference,
} from "@/lib/i18n/context";
import { formatDateWithWeekday } from "@/lib/date-format";
import {
invalidateKeys,
medicationDependentKeys,
@@ -152,8 +157,9 @@ export function DoseHistoryLedger({
schedules,
windowDays = 90,
}: DoseHistoryLedgerProps) {
const { t } = useTranslations();
const { t, locale } = useTranslations();
const fmt = useFormatters();
const dateFormatPref = useDateFormatPreference();
const { user } = useAuth();
const queryClient = useQueryClient();
const timeZone = user?.timezone || "Europe/Berlin";
@@ -437,7 +443,12 @@ export function DoseHistoryLedger({
data-day={group.dayKey}
>
<h3 className="text-muted-foreground px-1 text-xs font-medium">
{fmt.dateWithWeekday(new Date(`${group.dayKey}T00:00:00`))}
{/* Issue #490 — `dayKey` is a profile-timezone calendar day.
The old browser-local-midnight parse re-interpreted it in
the DEVICE zone and could shift the heading a day when
browser ≠ profile zone; the day-key label renders
UTC-pinned instead (zone-independent, weekday included). */}
{formatDateWithWeekday(group.dayKey, dateFormatPref, locale)}
</h3>
<ul className="border-border/60 divide-border/60 divide-y rounded-md border">
{group.rows.map((row, i) => (
@@ -9,7 +9,11 @@ import { MedicationStateBadges } from "@/components/medications/card-parts/medic
import { MedicationCardBody } from "@/components/medications/card-parts/medication-card-body";
import { useMedicationIntake } from "@/components/medications/use-medication-intake";
import { useWeekdayLabel } from "@/components/medications/card-parts/medication-next-last-slot";
import { useTranslations, useFormatters } from "@/lib/i18n/context";
import {
useTranslations,
useFormatters,
useDisplayTimezone,
} from "@/lib/i18n/context";
import {
invalidateKeys,
medicationDependentKeys,
@@ -19,6 +23,7 @@ import { apiGet, apiPost } from "@/lib/api/api-fetch";
import { formatDateTime, formatTime } from "@/lib/format";
import { getMedicationCategoryLabel } from "@/lib/medications/category-label";
import { formatDose } from "@/lib/medications/format-dose";
import { getDayOfWeekInTz } from "@/lib/tz/local-day";
import { type InjectionSiteKey } from "@/lib/medications/injection-sites";
import { LogInjectionSiteDialog } from "@/components/medications/log-injection-site-dialog";
import { useGlobalExcludedInjectionSites } from "@/lib/medications/use-injection-site-prefs";
@@ -185,6 +190,11 @@ export function Glp1MedicationCard({
const { user } = useAuth();
const userTz = user?.timezone || "Europe/Berlin";
const fmt = useFormatters();
// Issue #490 — the zone `fmt` renders dates in (mirror → Berlin). The
// weekday name paired with `fmt.dateShort` must be derived in this SAME
// zone: `Date.getDay()` reads the BROWSER zone and could name a weekday
// that contradicts the date printed next to it.
const displayTz = useDisplayTimezone();
const weekdayLabel = useWeekdayLabel();
const [, forceUpdate] = useReducer((x: number) => x + 1, 0);
// v1.8.5 — post-dose injection-site prompt (see medication-card.tsx).
@@ -403,7 +413,7 @@ export function Glp1MedicationCard({
if (!next) return null;
if (next.daysAway === 0) return t("medications.glp1NextInjectionToday");
if (next.daysAway === 1) return t("medications.glp1NextInjectionTomorrow");
const dayName = weekdayLabel(next.date.getDay());
const dayName = weekdayLabel(getDayOfWeekInTz(next.date, displayTz));
const dateShort = fmt.dateShort(next.date);
return t("medications.glp1NextInjectionDays", {
label: `${dayName}, ${dateShort}`,
@@ -453,7 +463,7 @@ export function Glp1MedicationCard({
medication.nextDueOverdue && next
? diffDays(next.date, now) === 0
? formatTime(next.date.toISOString())
: `${weekdayLabel(next.date.getDay())}, ${fmt.dateShort(next.date)}`
: `${weekdayLabel(getDayOfWeekInTz(next.date, displayTz))}, ${fmt.dateShort(next.date)}`
: null;
const nextLine =
@@ -21,7 +21,12 @@ import {
summariseCadence,
type MedicationPayload,
} from "@/components/medications/wizard/wizard-payload";
import { useTranslations, useFormatters } from "@/lib/i18n/context";
import {
useTranslations,
useFormatters,
useDateFormatPreference,
} from "@/lib/i18n/context";
import { formatDate as formatCalendarDate } from "@/lib/date-format";
export interface MedicationDetailSummaryProps {
name: string;
@@ -58,8 +63,9 @@ export function MedicationDetailSummary({
asNeeded = false,
startsOn,
}: MedicationDetailSummaryProps) {
const { t } = useTranslations();
const { t, locale } = useTranslations();
const formatters = useFormatters();
const dateFormatPref = useDateFormatPreference();
const status = resolveStatus(active, endsOn);
const statusLabel =
@@ -80,10 +86,15 @@ export function MedicationDetailSummary({
? "bg-warning"
: "bg-muted-foreground";
// Issue #490 — `Medication.startsOn` is a `@db.Date` calendar date
// (serialised as UTC midnight). The old `formatters.dateTime(startsOn)`
// re-read that instant in the display zone: it invented a meaningless
// clock time and shifted the day for zones west of UTC. A calendar date
// renders UTC-pinned (date only), correct in every zone.
const cadenceLine = oneShot
? startsOn
? t("medications.detail.cadence.oneShotOn", {
date: formatters.dateTime(startsOn),
date: formatCalendarDate(new Date(startsOn), dateFormatPref, locale),
})
: t("medications.detail.cadence.oneShotPending")
: asNeeded
@@ -215,6 +215,12 @@ export function ScheduleHistoryTimeline({
</span>
)}
</p>
{/* `validFrom` / `validUntil` (like `currentSince`
above) are real era-boundary instants
(`@db.Timestamptz`, the moment an edit archived the
plan) — NOT `@db.Date` calendar dates — so the
profile-timezone formatter renders the correct
local day (issue #490 audit). */}
<p className="text-muted-foreground text-xs tabular-nums">
{fmt.date(revision.validFrom)}
{" – "}