Skip to content

A FHIR Month Padded to Midnight

  • Timestamps in HL7 and FHIR clinical data: a precision set by what is sent, and a time with no offset, which HL7 reads as local time and FHIR refuses.

A FHIR Month Padded to Midnight

A FHIR resource sends a date as 2024-06, a month. The receiving system turns it into an instant to compare it with a range.

The naive approach

// The naive approach: a month read as the moment it starts
const value = "2024-06"; // a FHIR date: the month of June
new Date(value).toISOString();
// "2024-06-01T00:00:00.000Z" — a day and a time nobody sent

// Or pad it to a full date first
Temporal.PlainDate.from(value + "-01").toString();
// "2024-06-01" — the first of the month

Watch it break

The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.

Why

FHIR allows a date to stop at a year or a month, and 2024-06 states June 2024 and nothing finer. Padding it, with new Date or with -01, turns the month into one day, or one midnight. A range check then counts the whole month as its first moment, so a month that runs past the end of the range passes because its first day is inside it. parseFHIR keeps the precision and pads nothing, so the month stays a month.

The gmt approach

import { parseFHIR } from "@northguild/gmt/healthcare/parse";

parseFHIR("2024-06");
// { value: "2024-06", precision: "month", offset: "" }

parseFHIR("2024-06-15");
// { value: "2024-06-15", precision: "day", offset: "" }

parseFHIR("2024-6-15");
// null — the month is not padded

Same widget, working

output 

In the widget, try 2024-06, then 2024-06-15, then 2024-06-15T10:30:00. The first is a month, the second is a day, and the third is null, because a FHIR time needs a zone. The full rules are in Healthcare: Clinical Timestamps.

© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.