View Source DateConverter (Dsv v0.2.1)
Convert String
to one of the Date
, DateTime
, Time
or NaiveDateTime
types.
Summary
Functions
Convert the date String
parameter to the Date
/DateTime
/NaiveDateTime
/Time
based on the format of the provided string.
Examples
A simple date in the format YYYY-MM-DD
(iso8601) will be converted to the Date
type.
iex> DateConverter.convert("2020-10-11")
Date.new(2020, 10, 11)
iex> DateConverter.convert("2020-22-11")
{:error, :invalid_date}
String in the form of YYYY-MM-DD hh:mm::ss
will be converted to NaiveDateTime
struct.
iex> DateConverter.convert("2020-10-11 11:34:48")
NaiveDateTime.new(2020, 10, 11, 11, 34, 48)
iex> DateConverter.convert("2020-10-11 11:34:78")
{:error, :invalid_time}
String in the form of YYYY-MM-DDThh:mm::ss
will be converted to DateTime
struct.
iex> DateConverter.convert("2020-10-11T11:34:48.00Z")
DateTime.new(~D[2020-10-11], ~T[11:34:48.00])
iex> DateConverter.convert("2020-10-11T11:34:78.00Z")
{:error, :invalid_time}
String in the form of hh:mm:ss.
will be converted to Time
struct.
iex> DateConverter.convert("11:34:48")
Time.new(11, 34, 48)