Date/Time (DTM) -- HL7v2 primitive data type.
Format: YYYY[MM[DD[HH[MM[SS[.S[S[S[S]]]]]]]]][+/-ZZZZ]
Parses to a %DTM{} struct preserving all fields for lossless round-trip
encoding. Timezone offsets (including malformed ones) are stored verbatim
in the offset field so that encode/1 reproduces the exact wire format.
Encodes back to the canonical HL7v2 format.
Summary
Functions
Encodes a DTM value back to HL7v2 format.
Parses a DTM string into a DateTime, NaiveDateTime, or partial DTM struct.
Types
@type t() :: %HL7v2.Type.DTM{ day: pos_integer() | nil, fraction: binary() | nil, hour: non_neg_integer() | nil, minute: non_neg_integer() | nil, month: pos_integer() | nil, offset: binary() | nil, original: term(), second: non_neg_integer() | nil, year: pos_integer() }
Functions
@spec encode(t() | DateTime.t() | NaiveDateTime.t() | nil) :: binary()
Encodes a DTM value back to HL7v2 format.
Examples
iex> HL7v2.Type.DTM.encode(%HL7v2.Type.DTM{year: 2026, month: 3, day: 22, hour: 14, minute: 30})
"202603221430"
iex> HL7v2.Type.DTM.encode(%HL7v2.Type.DTM{year: 2026, month: 3, day: 22, hour: 14, minute: 30, second: 22, fraction: "1234", offset: "+0100"})
"20260322143022.1234+0100"
iex> HL7v2.Type.DTM.encode(nil)
""
Parses a DTM string into a DateTime, NaiveDateTime, or partial DTM struct.
Examples
iex> HL7v2.Type.DTM.parse("20260322143022.1234+0100")
%HL7v2.Type.DTM{year: 2026, month: 3, day: 22, hour: 14, minute: 30, second: 22, fraction: "1234", offset: "+0100"}
iex> HL7v2.Type.DTM.parse("20260322")
%HL7v2.Type.DTM{year: 2026, month: 3, day: 22}
iex> HL7v2.Type.DTM.parse("2026")
%HL7v2.Type.DTM{year: 2026}
iex> HL7v2.Type.DTM.parse("")
nil
iex> HL7v2.Type.DTM.parse(nil)
nil