formatFHIR
Signature
Section titled “Signature”formatFHIR(value: string, type: FhirDateType, options?: FhirFormatOptions): stringWrite an ISO 8601 string as a FHIR R4 date, dateTime or instant: the inverse of parseFHIR.
-
FHIR R4 Datatypes §2.24.0.1 limits each type:
dateisYYYY,YYYY-MMorYYYY-MM-DDwith no time zone;dateTimeadds a time that SHALL carry seconds and a zone;instantis at least to the second and SHALL include a zone.Type Precisions written Default precision dateyear, month, day the input’s, or day for an input with a time dateTimeyear, month, day, second, fraction the input’s instantsecond, fraction the input’s -
It cuts and never rounds, so the result never names a later second, day or month than the input’s own wall clock.
options.precisiononly lowers the precision; a finer one returns"". -
Under
date, the result is the wall-clock date at the input’s own offset (2024-06-15T23:30:00-05:00is2024-06-15), because §2.24.0.1 forbids a zone on adate. -
The designator is written as the input spells it (
Z,+00:00and-00:00stay as written;+05:30:00is written+05:30). The fraction always uses.. -
A second of
60returns"": §2.24.0.1 says “applications producing them MAY choose to avoid encoding leap seconds”. -
There is no hour or minute precision, and nothing is zero-filled: a value written to the hour or minute, with or without an offset, is written only when cut to a day or coarser (
2024-06-15T23-05:00is2024-06-15underdate). An hour-only time is ISO 8601-1 §5.3.1.3 reduced precision, which Temporal reads. -
An offset that is not a whole number of minutes returns
""(+02:00:30; Monrovia before 1972,Africa/Monrovia, was −0:44:30). This applies underdatetoo, even though adatenever writes the offset. -
Disambiguation: none, in the vocabulary of
LOCAL_TIME_RESOLUTION.md. A wall time with no offset is written only as a date. In a repeated hour at the end of DST, the offset decides which one is written. -
Annotations: none is read. A bracket of any kind (a zone,
[u-ca=iso8601],[foo=bar]) returns""; write the wall clock with the zone’s offset instead. -
Never throws: any failure, for input of any type, is
"". The matching reader isparseFHIR.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO 8601 date, date-time, or date-time with an offset |
type | FhirDateType | The FHIR type to write |
Options
Section titled “Options”options
How much of the value is written
Options for formatFHIR.
import type { FhirFormatOptions } from "@northguild/gmt";| Option | Type | Default | Description |
|---|---|---|---|
precision? | "year" | "month" | "day" | "second" | "fraction" (FhirPrecision) | the input’s precision, or "day" under date for an input finer than a day | The precision to write, no finer than the input’s. |
Returns
Section titled “Returns”the FHIR value, or "" when the value cannot be written as type
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatFHIR } from "@northguild/gmt/healthcare/format";
formatFHIR("2024-06-15T23:30:00-05:00", "date") // "2024-06-15"Source
Section titled “Source”© 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.