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
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 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"
NOTE: Code taken from https://github.com/ueberauth/guardian/blob/master/lib/guardian/utils.ex