curator v0.1.0 Curator.Time

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

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

Summary

Functions

Test if a datetime has expired

Shift a Ecto.DateTime or DateTime

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

Shift a Ecto.DateTime (in the opposite direction)

Functions

expired?(datetime, opts)
expired?(nil | struct, Keyword.t) :: boolean

Test if a datetime has expired.

Convert the datetime from Ecto.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> Ecto.DateTime.utc
...> |> Curator.Time.expired?(days: 1)
false

iex> Ecto.DateTime.utc
...> |> Curator.Time.shift(days: -2)
...> |> Ecto.DateTime.cast!
...> |> Curator.Time.expired?(days: 1)
true
shift(datetime, opts)
shift(struct, Keyword.t) :: struct

Shift a Ecto.DateTime or DateTime

Examples

iex> Ecto.DateTime.cast!("2016-10-10 10:10:10")
...> |> Curator.Time.shift(days: -2)
...> |> Ecto.DateTime.cast!
...> |> to_string
"2016-10-08 10:10:10"
timestamp()

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

unshift(datetime, list)
unshift(struct, Keyword.t) :: struct

Shift a Ecto.DateTime (in the opposite direction).

Examples

iex> Ecto.DateTime.cast!("2016-10-10 10:10:10")
...> |> Curator.Time.unshift(days: 2)
...> |> Ecto.DateTime.cast!
...> |> to_string
"2016-10-08 10:10:10"