View Source Rivet.Utils.Time (rivet_utils v2.0.5)
Contributor: Brandon Gillespie
Summary
Functions
Provide the time in a "x hours/mins/seconds/etc" ago type format. Options. Time can be provided as posix epoch (preferred), or DateTime, or NaiveDateTime.
Because posix epoch time is just easier to work with once you understand how it works.
this wraps the complexities brought on by Erlang being fancy with time, and gives us a conventional posix/epoch time value. The time value to return is specified by the first argument, as an atom, and is a required argument (to remove ambiguity), from the set
start_datetime_of_posix_interval/4.
utc_hours_since_midnight_sunday/0.
Functions
Provide the time in a "x hours/mins/seconds/etc" ago type format. Options. Time can be provided as posix epoch (preferred), or DateTime, or NaiveDateTime.
since: time
— compare vs this time instead of "now"format: :long | :short(default) | :abbrev
- long format uses no shortened words (minute, second)
- short (default) uses 'min' and 'sec' instead of the longer forms
- abbrev uses one and two character abbreviations
space: " "
(default)
Examples:
iex> (epoch_time() - 60) |> ago() "1 min"
iex> (epoch_time() - 11000) |> ago() "3 hours"
iex> DateTime.from_unix!(epoch_time() - 86400) |> ago(format: :abbrev, space: "") "1d"
iex> ago(epoch_time() - 300, format: :long) "5 minutes"
iex> t_start = epoch_time() - 900 iex> t_end = epoch_time() - 300 iex> ago(t_start, since: t_end, format: :long) "10 minutes" iex> ago(t_end, since: t_start, format: :long) "10 minutes"
Because posix epoch time is just easier to work with once you understand how it works.
this wraps the complexities brought on by Erlang being fancy with time, and gives us a conventional posix/epoch time value. The time value to return is specified by the first argument, as an atom, and is a required argument (to remove ambiguity), from the set:
:second, :millisecond, :microsecond or :nanosecond
It also uses their best value for 'monotonic' time so the clock will not go backwards.
For the full story see: https://hexdocs.pm/elixir/System.html http://erlang.org/doc/apps/erts/time_correction.html
start_datetime_of_posix_interval(datetime, interval, atom, num_of_intervals_back_or_forward)
View Source@spec start_datetime_of_posix_interval( DateTime.t(), integer(), interval_unit :: :second | :millisecond, integer() ) :: DateTime.t()
start_datetime_of_posix_interval/4.
Suppose you have a DateTime that is 30 seconds past the beginning of a given minute. If the interval is 60_000 milliseconds (1 min.), then the beginning of the next posix interval is 30 seconds later- this returns that datetime.
@spec utc_hours_since_midnight_sunday() :: 0..167
utc_hours_since_midnight_sunday/0.
There are 168 hours in a week, we zero-index them from 12:00:00 a.m. UTC Sunday.