HL7v2.Type.TM (HL7v2 v3.10.1)

Copy Markdown View Source

Time (TM) -- HL7v2 primitive data type.

Format: HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]

Parses to a %TM{} struct preserving all fields for lossless round-trip encoding. Similar to DTM but without the date portion.

Summary

Functions

Encodes a TM value back to HL7v2 format.

Parses a TM string into a %TM{} struct.

Types

t()

@type t() :: %HL7v2.Type.TM{
  fraction: binary() | nil,
  hour: non_neg_integer(),
  minute: non_neg_integer() | nil,
  offset: binary() | nil,
  original: term(),
  second: non_neg_integer() | nil
}

Functions

encode(tm)

@spec encode(t() | nil) :: binary()

Encodes a TM value back to HL7v2 format.

Examples

iex> HL7v2.Type.TM.encode(%HL7v2.Type.TM{hour: 14, minute: 30})
"1430"

iex> HL7v2.Type.TM.encode(%HL7v2.Type.TM{hour: 14, minute: 30, second: 22, fraction: "1234", offset: "+0100"})
"143022.1234+0100"

iex> HL7v2.Type.TM.encode(nil)
""

parse(value)

@spec parse(binary() | nil) :: t() | nil

Parses a TM string into a %TM{} struct.

Examples

iex> HL7v2.Type.TM.parse("143022.1234+0100")
%HL7v2.Type.TM{hour: 14, minute: 30, second: 22, fraction: "1234", offset: "+0100"}

iex> HL7v2.Type.TM.parse("1430")
%HL7v2.Type.TM{hour: 14, minute: 30}

iex> HL7v2.Type.TM.parse("14")
%HL7v2.Type.TM{hour: 14}

iex> HL7v2.Type.TM.parse("")
nil

iex> HL7v2.Type.TM.parse(nil)
nil