every v0.0.4 Every

Every gives you ability to use Process.send_after/3 with calculated intervals which can be rounded to every (note: all functions return values only in seconds)

  1. Minute,
  2. N minutes,
  3. Hour,
  4. N Hours.

Every method accepts optional relative_to parameter if it is provided then duration in seconds until next call will be calculated relative to given relative_to.

Link to this section Summary

Functions

Calculate interval until next day

Calculate how many minutes left until next hour starts

Calculate how many minutes left until next hour starts

Calculate how many seconds left until next minute starts

Calculate how many minutes left until next interval

Link to this section Functions

Link to this function day(relative_to \\ Timex.now())

Calculate interval until next day.

If relative_to DateTime is not provided then current moment in time is used.

Returns: integer number of seconds.

Example

iex> {:ok, now, _} = DateTime.from_iso8601("2018-10-14T16:48:12.000Z")
iex> Every.day(now)
25908
Link to this function hour(relative_to \\ Timex.now())

Calculate how many minutes left until next hour starts.

If relative_to DateTime is not provided then current moment in time is used.

Returns: integer number of seconds.

Example

iex> {:ok, now, _} = DateTime.from_iso8601("2018-10-14T16:48:12.000Z")
iex> Every.hour(now)
768
Link to this function hours(interval, relative_to)

Calculate how many minutes left until next hour starts.

If relative_to DateTime is not provided then current moment in time is used.

Returns: integer number of seconds.

Example

iex> {:ok, now, _} = DateTime.from_iso8601("2018-10-14T16:48:12.000Z")
iex> Every.hour(now)
768
Link to this function minute(relative_to \\ Timex.now())

Calculate how many seconds left until next minute starts.

If relative_to DateTime is not provided then current moment in time is used.

Returns: integer number of seconds.

Example

iex> {:ok, now, _} = DateTime.from_iso8601("2018-10-14T16:48:12.000Z")
iex> Every.minute(now)
48
Link to this function minutes(interval, relative_to)

Calculate how many minutes left until next interval.

If relative_to DateTime is not provided then current moment in time is used.

Returns: integer number of seconds.

Example

iex> {:ok, now, _} = DateTime.from_iso8601("2018-10-14T16:48:12.000Z")
iex> Every.minutes(5, now)  # 16:50 > 15:50:00 - 16:48:12
108