Calendar v1.0.0 Calendar.NaiveDateTime.Parse View Source
Link to this section Summary
Link to this section Functions
Link to this function
asctime(string) View Source
Parses a "C time" string.
Examples
iex> Calendar.NaiveDateTime.Parse.asctime("Wed Apr 9 07:53:03 2003")
{:ok, %NaiveDateTime{year: 2003, month: 4, day: 9, hour: 7, minute: 53, second: 3, microsecond: {0, 0}}}
iex> asctime("Thu, Apr 10 07:53:03 2003")
{:ok, %NaiveDateTime{year: 2003, month: 4, day: 10, hour: 7, minute: 53, second: 3, microsecond: {0, 0}}}
Link to this function
asctime!(string) View Source
Like asctime/1
, but returns the result without tagging it with :ok.
Examples
iex> asctime!("Wed Apr 9 07:53:03 2003")
%NaiveDateTime{year: 2003, month: 4, day: 9, hour: 7, minute: 53, second: 3, microsecond: {0, 0}}
iex> asctime!("Thu, Apr 10 07:53:03 2003")
%NaiveDateTime{year: 2003, month: 4, day: 10, hour: 7, minute: 53, second: 3, microsecond: {0, 0}}
Link to this function
asn1_generalized(string) View Source
Parse ASN.1 GeneralizedTime.
Returns tuple with {:ok, [NaiveDateTime], UTC offset (optional)}
Examples
iex> "19851106210627.3" |> asn1_generalized
{:ok, %NaiveDateTime{year: 1985, month: 11, day: 6, hour: 21, minute: 6, second: 27, microsecond: {300_000, 1}}, nil}
iex> "19851106210627.3Z" |> asn1_generalized
{:ok, %NaiveDateTime{year: 1985, month: 11, day: 6, hour: 21, minute: 6, second: 27, microsecond: {300_000, 1}}, 0}
iex> "19851106210627.3-5000" |> asn1_generalized
{:ok, %NaiveDateTime{year: 1985, month: 11, day: 6, hour: 21, minute: 6, second: 27, microsecond: {300_000, 1}}, -180000}
Link to this function
iso8601(string) View Source
Parses an ISO8601 datetime. Returns {:ok, NaiveDateTime struct, UTC offset in secods} In case there is no UTC offset, the third element of the tuple will be nil.
Examples
# With offset
iex> iso8601("1996-12-19T16:39:57-0200")
{:ok, %NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, minute: 39, second: 57, microsecond: {0, 0}}, -7200}
# Without offset
iex> iso8601("1996-12-19T16:39:57")
{:ok, %NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, minute: 39, second: 57, microsecond: {0, 0}}, nil}
# With fractional seconds
iex> iso8601("1996-12-19T16:39:57.123")
{:ok, %NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, minute: 39, second: 57, microsecond: {123000, 3}}, nil}
# With fractional seconds
iex> iso8601("1996-12-19T16:39:57,123")
{:ok, %NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, minute: 39, second: 57, microsecond: {123000, 3}}, nil}
# With Z denoting 0 offset
iex> iso8601("1996-12-19T16:39:57Z")
{:ok, %NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, minute: 39, second: 57, microsecond: {0, 0}}, 0}
# Invalid date
iex> iso8601("1996-13-19T16:39:57Z")
{:error, :invalid_datetime, nil}