Calendar.NaiveDateTime.Parse

Summary

asctime(string)

Parses a "C time" string

iso8601(string)

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

Functions

asctime(string)

Parses a "C time" string.

Examples

iex> Calendar.NaiveDateTime.Parse.asctime("Wed Apr  9 07:53:03 2003")
{:ok, %Calendar.NaiveDateTime{year: 2003, month: 4, day: 9, hour: 7, min: 53, sec: 3, usec: nil}}
iex> asctime("Thu, Apr 10 07:53:03 2003")
{:ok, %Calendar.NaiveDateTime{year: 2003, month: 4, day: 10, hour: 7, min: 53, sec: 3, usec: nil}}
iso8601(string)

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, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, -7200}

# Without offset
iex> iso8601("1996-12-19T16:39:57")
{:ok, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, nil}

# With Z denoting 0 offset
iex> iso8601("1996-12-19T16:39:57Z")
{:ok, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, 0}

# Invalid date
iex> iso8601("1996-13-19T16:39:57Z")
{:error, :invalid_datetime, nil}