View Source ExDicom.Util.TMParser (EX_DICOM v0.1.0)

Parses TM formatted strings into a map with time components. The TM format expects strings in the format HHMMSS.FFFFFF where:

  • HH represents hours (00-23)
  • MM represents minutes (00-59)
  • SS represents seconds (00-59)
  • FFFFFF represents fractional seconds (000000-999999)

Summary

Functions

Parses a TM formatted string into a map with time components.

Types

time_components()

@type time_components() :: %{
  hours: integer(),
  minutes: integer() | nil,
  seconds: integer() | nil,
  fractional_seconds: integer() | nil
}

Functions

parse(time, validate \\ false)

@spec parse(String.t(), boolean()) ::
  {:ok, time_components() | nil} | {:error, String.t()}

Parses a TM formatted string into a map with time components.

Parameters

  • time - String in TM VR format
  • validate - Boolean indicating whether to validate the time components

Returns

  • {:ok, map} with time components if valid
  • {:error, string} with error message if invalid and validate is true
  • {:ok, nil} if input is invalid and validate is false

Examples

iex> TMParser.parse("14")
{:ok, %{hours: 14, minutes: nil, seconds: nil, fractional_seconds: nil}}

iex> TMParser.parse("1430")
{:ok, %{hours: 14, minutes: 30, seconds: nil, fractional_seconds: nil}}

iex> TMParser.parse("143022.123")
{:ok, %{hours: 14, minutes: 30, seconds: 22, fractional_seconds: 123000}}

iex> TMParser.parse("24", true)
{:error, "invalid TM '24'"}