curator v0.2.4 Curator.Time View Source
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
Link to this section 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)
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 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
Link to this function
unshift(datetime, list)
View Source
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"