View Source ExDicom.Util.DAParser (EX_DICOM v0.2.0)
Parses DA formatted date strings into maps with date components. The DA format expects strings in the format YYYYMMDD where:
- YYYY represents the year
- MM represents the month (01-12)
- DD represents the day (01-31, depending on month)
Summary
Functions
Returns the number of days in the given month for a specific year.
Parses a DA formatted string into a map with date components.
Types
Functions
Returns the number of days in the given month for a specific year.
Examples
iex> DAParser.days_in_month(2, 2024)
29
iex> DAParser.days_in_month(2, 2023)
28
iex> DAParser.days_in_month(4, 2024)
30
@spec parse(String.t(), boolean()) :: {:ok, date_components() | nil} | {:error, String.t()}
Parses a DA formatted string into a map with date components.
Parameters
- date - String in DA format (YYYYMMDD)
- validate - Boolean indicating whether to validate the date components
Returns
{:ok, map}
with date 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> DAParser.parse("20240131")
{:ok, %{year: 2024, month: 1, day: 31}}
iex> DAParser.parse("20240229")
{:ok, %{year: 2024, month: 2, day: 29}}
iex> DAParser.parse("20230229", true)
{:error, "invalid DA '20230229'"}