UTC DateTime v0.0.1 UTCDateTime View Source
A datetime implementation constraint to UTC.
Link to this section Summary
Functions
A datetime implementation constraint to UTC.
Converts the given datetime
into a UTCDateTime
.
Converts the given NaiveDateTime
to UTCDateTime
.
Handles the sigil ~Z
to create a UTCDateTime
.
Converts the given UTCDateTime
to NaiveDateTime
.
Converts the given UTCDateTime
into a NaiveDateTime
.
Placeholder
Returns the current UTC datetime.
Link to this section Types
t()
View Sourcet() :: %UTCDateTime{ day: Calendar.day(), hour: Calendar.hour(), microsecond: Calendar.microsecond(), minute: Calendar.minute(), month: Calendar.month(), second: Calendar.second(), year: Calendar.year() }
A datetime implementation constraint to UTC.
Link to this section Functions
A datetime implementation constraint to UTC.
from_datetime(datetime)
View Sourcefrom_datetime(DateTime.t()) :: UTCDateTime.t()
Converts the given datetime
into a UTCDateTime
.
Any datetime
with a none UTC time zone will be converted to UTC.
Examples
iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "UTC",
...> hour: 23, minute: 0, second: 7, microsecond: {0, 1},
...> utc_offset: 0, std_offset: 0, time_zone: "Etc/UTC"}
iex> UTCDateTime.from_datetime(dt)
~Z[2000-02-29 23:00:07.0]
iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET",
...> hour: 23, minute: 0, second: 7, microsecond: {0, 1},
...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"}
iex> UTCDateTime.from_datetime(dt)
~Z[2000-02-29 22:00:07.0]
Converts the given NaiveDateTime
to UTCDateTime
.
It expects the given naive_datetime
to be in the "Etc/UTC" time zone.
Examples
iex> UTCDateTime.from_naive(~N[2016-05-24 13:26:08.003])
~Z[2016-05-24 13:26:08.003]
Handles the sigil ~Z
to create a UTCDateTime
.
By default, this sigil requires UTC date times to be written in the ISO8601 format:
~Z[yyyy-mm-dd hh:mm:ssZ]
~Z[yyyy-mm-dd hh:mm:ss.ssssssZ]
~Z[yyyy-mm-ddThh:mm:ss.ssssss+00:00]
such as:
~Z[2015-01-13 13:00:07Z]
~Z[2015-01-13T13:00:07.123+00:00]
The given utc_datetime_string
must include "Z" or "00:00" offset
which marks it as UTC, otherwise an error is raised.
The lower case ~z
variant does not exist as interpolation
and escape characters are not useful for date time sigils.
More information on date times can be found in the UTCDateTime
module.
Examples
iex> ~Z[2015-01-13 13:00:07Z]
~Z[2015-01-13 13:00:07Z]
iex> ~Z[2015-01-13T13:00:07.001+00:00]
~Z[2015-01-13 13:00:07.001Z]
to_datetime(utc_datetime, calendar \\ Calendar.ISO)
View Sourceto_datetime(UTCDateTime.t(), Calendar.calendar()) :: DateTime.t()
Converts the given UTCDateTime
to NaiveDateTime
.
The given utc_datetime
does not contain a calendar,
so Calendar.ISO
is set by default.
It is possible to manually pass a different calendar.
Examples
iex> UTCDateTime.to_datetime(~Z[2016-05-24 13:26:08.003])
~U[2016-05-24 13:26:08.003Z]
to_naive(utc_datetime, calendar \\ Calendar.ISO)
View Sourceto_naive(UTCDateTime.t(), Calendar.calendar()) :: NaiveDateTime.t()
Converts the given UTCDateTime
into a NaiveDateTime
.
The given utc_datetime
does not contain a calendar,
so Calendar.ISO
is set by default.
It is possible to manually pass a different calendar.
Examples
iex> dt = %UTCDateTime{year: 2016, month: 5, day: 24, ...> hour: 13, minute: 26, second: 8, ...> microsecond: {3000, 3}} iex> UTCDateTime.to_naive(dt) ~N[2016-05-24 13:26:08.003]
Placeholder
Convert utc_datetime
to RFC3339
string format.
Examples
iex> UTCDateTime.to_rfc3339(~Z[2019-12-14 08:06:24.289659])
"2019-12-14 08:06:24.289659"
Returns the current UTC datetime.
Examples
iex> utc_datetime = UTCDateTime.utc_now()
iex> utc_datetime.year >= 2016
true