Swiss.DateTime (swiss v3.12.0) View Source

Some extra functions for working with DateTimes that aren't in the native lib or on Timex.

Link to this section Summary

Functions

Converts a ISO 8601 date into a DateTime and offset.

Returns the biggest (latest) of the given list of datetimes.

Returns the biggest (latest) of two datetimes.

Returns the smallest (earliest) of the given list of datetimes.

Returns the smallest (earliest) of two datetimes.

Helper method for getting "now" with second precision.

Link to this section Functions

Link to this function

from_iso8601!(iso_date, calendar \\ Calendar.ISO)

View Source

Converts a ISO 8601 date into a DateTime and offset.

This is a wrapper around DateTime.from_iso8601/2 that raises on error.

Examples

iex> Swiss.DateTime.from_iso8601!("2015-01-23T23:50:07Z")
{~U[2015-01-23 23:50:07Z], 0}

Specs

max([DateTime.t()]) :: DateTime.t()

Returns the biggest (latest) of the given list of datetimes.

Examples

iex> Swiss.DateTime.max([DateTime.from_unix!(1_577_664_000), DateTime.from_unix!(2_464_096_360), DateTime.from_unix!(1_464_096_368)])
~U[2048-01-31 15:12:40Z]

iex> Swiss.DateTime.max([DateTime.from_unix!(2_464_096_360), nil])
~U[2048-01-31 15:12:40Z]

iex> Swiss.DateTime.max([nil, nil, ~U[2020-11-09 09:00:50Z]])
~U[2020-11-09 09:00:50Z]

Specs

Returns the biggest (latest) of two datetimes.

Examples

iex> Swiss.DateTime.max(DateTime.from_unix!(1_577_664_000), DateTime.from_unix!(1_464_096_368))
~U[2019-12-30 00:00:00Z]

Specs

min([DateTime.t()]) :: DateTime.t()

Returns the smallest (earliest) of the given list of datetimes.

Examples

iex> Swiss.DateTime.min([DateTime.from_unix!(1_577_664_000), DateTime.from_unix!(2_464_096_360), DateTime.from_unix!(1_464_096_368)])
~U[2016-05-24 13:26:08Z]

iex> Swiss.DateTime.min([DateTime.from_unix!(2_464_096_360), nil])
~U[2048-01-31 15:12:40Z]

iex> Swiss.DateTime.min([nil, nil, ~U[2020-11-09 09:00:50Z]])
~U[2020-11-09 09:00:50Z]

Specs

Returns the smallest (earliest) of two datetimes.

Examples

iex> Swiss.DateTime.min(DateTime.from_unix!(1_577_664_000), DateTime.from_unix!(1_464_096_368))
~U[2016-05-24 13:26:08Z]

Specs

second_utc_now() :: DateTime.t()

Helper method for getting "now" with second precision.