mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
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:
1 parent
4ac05364fe
commit
838629276c
10 files changed
+111
-11
No files matched your search
@@ -39,6 +39,7 @@ import type {
|
||||
MedicationStatementFactData,
|
||||
ObservationFactData,
|
||||
} from "@/lib/validations/inbound-documents";
|
||||
import { dateOnlyAtNoonUtc, isDateOnlyKey } from "@/lib/tz/date-only";
|
||||
|
||||
/** A per-fact commit failure the caller maps to a per-fact 422 entry. */
|
||||
export class FactCommitError extends Error {
|
||||
@@ -55,11 +56,13 @@ export interface CommittedRecordRef {
|
||||
recordId: string;
|
||||
}
|
||||
|
||||
/** Parse a stated YYYY-MM-DD into a UTC instant, or fall back to now. */
|
||||
/**
|
||||
* A stated YYYY-MM-DD as the instant a date-only value is stored at (noon
|
||||
* UTC), or now when the document states none. UTC midnight read back as the
|
||||
* previous day anywhere west of UTC.
|
||||
*/
|
||||
function statedDateOrNow(date: string | null): Date {
|
||||
if (date && /^\d{4}-\d{2}-\d{2}$/u.test(date)) {
|
||||
return new Date(`${date}T00:00:00.000Z`);
|
||||
}
|
||||
if (date && isDateOnlyKey(date)) return dateOnlyAtNoonUtc(date);
|
||||
return new Date();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user