fix(documents): store stated dates at noon UTC

A report's stated date, a document's filing date and the date a committed
lab reading or condition carries were written as UTC midnight, which is
the previous evening west of UTC: a reading dated the 1st showed on the
31st. Date-only values are now stored at noon UTC through one helper in
the time zone module, the convention the lab scan and the cycle engine
already use. Rows written at midnight still read back to the same date.
A document uploaded without a date files under the uploader's own day
rather than the UTC one.
This commit is contained in:
Marc-André Bombeck committed 2026-10-01 09:33:50 +02:00
1 parent 4ac05364fe
commit 838629276c
10 files changed
+111 -11

No files matched your search

@@ -28,6 +28,7 @@ import { prisma } from "@/lib/db";
import { resolveOrMintBiomarker } from "@/lib/labs/biomarker-store";
import { decryptFactData } from "@/lib/documents/store";
import type { ExtractedFact } from "@/generated/prisma/client";
import { userDayKey } from "@/lib/tz/format";
function observationFact(): ExtractedFact {
return {
@@ -94,5 +95,12 @@ describe("commitApprovedFact — OBSERVATION unit integrity", () => {
const ref = await commitApprovedFact("user-1", observationFact());
expect(ref).toEqual({ recordType: "labResult", recordId: "lr-1" });
expect(prisma.labResult.create).toHaveBeenCalledOnce();
// The stated date is stored at noon UTC: it reads back on the stated day
// as a UTC label and formatted in a zone west of UTC alike. UTC midnight
// showed the reading a day early there.
const takenAt = vi.mocked(prisma.labResult.create).mock.calls[0]![0].data
.takenAt as Date;
expect(takenAt.toISOString()).toBe("2025-01-01T12:00:00.000Z");
expect(userDayKey(takenAt, "America/Los_Angeles")).toBe("2025-01-01");
});
});