View Source Timex.Parse.DateTime.Parser (timex v3.7.11)

This is the base plugin behavior for all Timex date/time string parsers.

Link to this section Summary

Functions

Parses a date/time string using the default parser.

Parses a date/time string using the provided tokenizer. Tokenizers must implement the Timex.Parse.DateTime.Tokenizer behaviour.

Link to this section Functions

Link to this function

parse!(date_string, format_string, tokenizer \\ Default)

View Source
@spec parse!(String.t(), String.t(), atom() | nil) ::
  DateTime.t() | NaiveDateTime.t() | Timex.AmbiguousDateTime.t() | no_return()

Same as parse/2 and parse/3, but raises on error.

Link to this function

parse(date_string, format_string)

View Source
@spec parse(binary(), binary()) ::
  {:ok, DateTime.t() | NaiveDateTime.t() | Timex.AmbiguousDateTime.t()}
  | {:error, term()}

Parses a date/time string using the default parser.

examples

Examples

iex> use Timex
...> {:ok, dt} = Elixir.Timex.Parse.DateTime.Parser.parse("2014-07-29T00:20:41.196Z", "{ISO:Extended:Z}")
...> dt.year
2014
iex> dt.month
7
iex> dt.day
29
iex> dt.time_zone
"Etc/UTC"
Link to this function

parse(date_string, format_string, tokenizer)

View Source
@spec parse(binary(), binary(), atom()) ::
  {:ok, DateTime.t() | NaiveDateTime.t() | Timex.AmbiguousDateTime.t()}
  | {:error, term()}

Parses a date/time string using the provided tokenizer. Tokenizers must implement the Timex.Parse.DateTime.Tokenizer behaviour.

examples

Examples

iex> use Timex
...> {:ok, dt} = Elixir.Timex.Parse.DateTime.Parser.parse("2014-07-29T00:30:41.196-02:00", "{ISO:Extended}", Timex.Parse.DateTime.Tokenizers.Default)
...> dt.year
2014
iex> dt.month
7
iex> dt.day
29
iex> dt.time_zone
"Etc/UTC-2"