Function: dtmToDate()
dtmToDate(
parts,options?):Date|undefined
Materialize an absolute-instant JS Date from DtmParts: only on
explicit caller request. Truncated fields fill to their lowest legal value
(month → January, day → 1, time → 0) for instant construction only; the
value's stated precision still tells the truth.
Timezone resolution is honest:
- has an offset → the exact instant, using that offset;
- no offset +
assumeOffsetMinutessupplied → that offset is applied; - no offset + nothing supplied →
undefined(never a silent UTC guess).
Returns undefined for an invalid value or an unresolvable zone; never
throws.
Parameters
parts
options?
DtmToDateOptions = {}
Returns
Date | undefined
Example
import { parseDtm, dtmToDate } from "@cosyte/hl7";
dtmToDate(parseDtm("20250102153045-0500"))?.toISOString();
// "2025-01-02T20:30:45.000Z": exact, offset-derived
dtmToDate(parseDtm("20250102")); // undefined: refuses to guess the zone
dtmToDate(parseDtm("20250102"), { assumeOffsetMinutes: 0 })?.toISOString();
// "2025-01-02T00:00:00.000Z": caller explicitly assumed UTC