View Source Antikythera.Time (antikythera v0.5.1)
Data structure to represent date and time in milli-seconds resolution.
Note that all values of Antikythera.Time.t
are in UTC.
Poison.Encoder
protocol is implemented for Antikythera.Time.t
,
so that values of this type can be directly converted to Antikythera.IsoTimestamp.t
on Poison.encode/1
.
iex> Poison.encode(%{time: {Antikythera.Time, {2017, 1, 1}, {0, 0, 0}, 0}})
{:ok, "{\"time\":\"2017-01-01T00:00:00.000+00:00\"}"}
See also new/1
.
Summary
Functions
Parses HTTP-date formats into Antikythera.Time.t.
Convert timestamps into Antikythera.Time.t
or wrap valid Antikythera.Time.t
,
leveraging recursive_new?
option of Croma.Struct
.
Returns date/time in IMF-fixdate format.
Types
@type t() :: {Antikythera.Time, :calendar.date(), :calendar.time(), milliseconds()}
Functions
@spec from_epoch_milliseconds(Antikythera.MilliSecondsInGregorian.t()) :: t()
@spec from_http_date(String.t()) :: Croma.Result.t(t())
Parses HTTP-date formats into Antikythera.Time.t.
Supports IMF-fixdate format, RFC 850 format and ANSI C's asctime()
format for compatibility.
Note: An HTTP-date value must represents time in UTC(GMT). Thus timezone string in the end must always be 'GMT'. Any other timezone string (such as 'JST') will actually be ignored and parsed as GMT.
@spec from_iso_basic(String.t()) :: Croma.Result.t(t())
@spec from_iso_timestamp(String.t()) :: Croma.Result.t(t())
@spec new(any()) :: Croma.Result.t(t())
Convert timestamps into Antikythera.Time.t
or wrap valid Antikythera.Time.t
,
leveraging recursive_new?
option of Croma.Struct
.
Only Antikythera.IsoTimestamp.t
can be converted.
iex> {:ok, time} = Elixir.Antikythera.Time.new("2015-01-23T23:50:07Z")
{:ok, {Elixir.Antikythera.Time, {2015, 1, 23}, {23, 50, 7}, 0}}
iex> Elixir.Antikythera.Time.new(time)
{:ok, {Elixir.Antikythera.Time, {2015, 1, 23}, {23, 50, 7}, 0}}
iex> Elixir.Antikythera.Time.new("2015-01-23T23:50:07") |> Croma.Result.error?()
true
iex> Elixir.Antikythera.Time.new(nil) |> Croma.Result.error?()
true
@spec now() :: t()
@spec to_http_date(t()) :: Antikythera.ImfFixdate.t()
Returns date/time in IMF-fixdate format.
The format is subset of Internet Message Format (RFC5322, formarly RFC822, RFC1123). Defined as 'preferred' format in RFC7231 and modern web servers or clients should send in this format.
@spec to_iso_basic(t()) :: Antikythera.IsoTimestamp.Basic.t()
@spec to_iso_timestamp(t()) :: Antikythera.IsoTimestamp.t()