Function: parseV3DateTime()
parseV3DateTime(
value):Date|undefined
Parse a variable-precision HL7 v3 timestamp string to a JS Date. Accepts
year through second precision plus optional fractional seconds and an
optional ±HHMM (or ±HH) timezone offset. Per the CDA R2 / HL7 v3 TS
literal YYYYMMDDHHMMSS.UUUU[±ZZzz], a fraction or offset is accepted only
on a value that carries the time-of-day (at least the hour): a fraction or
offset hung on a bare YYYY/YYYYMM/YYYYMMDD value, e.g. the dropped-dash
"2026-0721", is rejected rather than silently misread. A value with no
offset resolves to UTC for determinism; truncated values resolve to the first
instant of the stated precision (e.g. 2026 → 2026-01-01T00:00:00Z).
Returns undefined when the value does not match the shape or is
calendar-invalid, never throws.
Parameters
value
string
Returns
Date | undefined
Example
import { parseV3DateTime } from "@cosyte/ccda";
parseV3DateTime("20260628")?.toISOString(); // "2026-06-28T00:00:00.000Z"
parseV3DateTime("20260628153045-0500")?.toISOString();
parseV3DateTime("not-a-date"); // undefined