View Source Datix.Time (datix v0.2.0)

A Time parser using Calendar.strftime format-string.

Link to this section Summary

Functions

Parses a date string according to the given format, erroring out for invalid arguments.

Parses a time string according to the given format.

Link to this section Functions

Link to this function

parse!(time_str, format, opts \\ [])

View Source
@spec parse!(String.t(), String.t() | Datix.compiled(), list()) :: Time.t()

Parses a date string according to the given format, erroring out for invalid arguments.

Link to this function

parse(time_str, format, opts \\ [])

View Source
@spec parse(String.t(), String.t() | Datix.compiled(), list()) ::
  {:ok, Time.t()}
  | {:error, :invalid_time}
  | {:error, :invalid_input}
  | {:error, {:parse_error, expected: String.t(), got: String.t()}}
  | {:error, {:conflict, expected: term(), got: term(), modifier: String.t()}}
  | {:error, {:invalid_string, [{:modifier, String.t()}]}}
  | {:error, {:invalid_integer, [{:modifier, String.t()}]}}
  | {:error, {:invalid_modifier, [{:modifier, String.t()}]}}

Parses a time string according to the given format.

See the Calendar.strftime documentation for how to specify a format-string.

options

Options

  • :calendar - the calendar to build the Time, defaults to Calendar.ISO

  • :preferred_time - a string for the preferred format to show times, it can't contain the %X format and defaults to "%H:%M:%S" if the option is not received

  • :am_pm_names - a keyword list with the names of the period of the day, defaults to [am: "am", pm: "pm"].

Missing values will be set to minimum.

examples

Examples

iex> Datix.Time.parse("11:12:55", "%X")
{:ok, ~T[11:12:55]}

iex> format = Datix.compile!("%X")
iex> Datix.Time.parse("11:12:55", format)
{:ok, ~T[11:12:55]}

iex> Datix.Time.parse("10 PM", "%I %p")
{:ok, ~T[22:00:00]}