curator v0.3.4 Curator.Time View Source

A Curator Helper Module to determine if DateTime’s have expired. This is usually used to see if a database stored token with a *_at timestamp has expired.

NOTE: Code originally taken from https://github.com/smpallen99/coherence/blob/master/web/controllers/controller_helpers.ex

Link to this section Summary

Functions

Test if a datetime has expired

Shift a DateTime

NOTE: Code taken from https://github.com/ueberauth/guardian/blob/master/lib/guardian/utils.ex

Shift a DateTime (in the opposite direction)

Link to this section Functions

Link to this function expired?(datetime, opts) View Source
expired?(nil | struct(), Keyword.t()) :: boolean()

Test if a datetime has expired.

Convert the datetime from DateTime format to Timex format to do the comparison given the time during in opts.

Examples

expired?(user.expire_at, days: 5)
expired?(user.expire_at, minutes: 10)

iex> DateTime.utc_now
...> |> Curator.Time.expired?(days: 1)
false

iex> DateTime.utc_now
...> |> Curator.Time.shift(days: -2)
...> |> Curator.Time.expired?(days: 1)
true
Link to this function shift(datetime, opts) View Source
shift(struct(), Keyword.t()) :: struct()

Shift a DateTime

Examples

iex> DateTime.from_naive!(~N[2016-10-10 10:10:10], "Etc/UTC")
...> |> Curator.Time.shift(days: -2)
...> |> to_string
"2016-10-08 10:10:10Z"

NOTE: Code taken from https://github.com/ueberauth/guardian/blob/master/lib/guardian/utils.ex

Link to this function unshift(datetime, list) View Source
unshift(struct(), Keyword.t()) :: struct()

Shift a DateTime (in the opposite direction).

Examples

iex> DateTime.from_naive!(~N[2016-10-10 10:10:10], "Etc/UTC")
...> |> Curator.Time.unshift(days: 2)
...> |> to_string
"2016-10-08 10:10:10Z"