Function: parseDtm()
parseDtm(
raw):DtmParts
Parse an HL7 v2 TS/DTM string into typed DtmParts, preserving the
stated precision and timezone fidelity. Never zero-fills a truncation,
never coerces to a Date, and never assumes UTC for a missing offset.
Returns { raw, valid: false, hasTimezone: false } (no parts) for empty,
malformed, or calendar-out-of-range input: never throws. A fractional
component is only accepted at full second precision.
Parameters
raw
string
Returns
Example
import { parseDtm } from "@cosyte/hl7";
parseDtm("1970");
// { raw: "1970", valid: true, precision: "year", year: 1970, hasTimezone: false }
parseDtm("20250102153045.5-0500");
// precision "fraction", fractionalSeconds "5", hasTimezone true, offsetMinutes -300
parseDtm("not-a-date");
// { raw: "not-a-date", valid: false, hasTimezone: false }