every v0.0.9 Every

Every gives you ability to use Process.send_after/3 with intervals which can be rounded to every:

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

Every function accepts an optional relative_to parameter, which can be used to fake the current moment in time. If it is not provided, the current time will be used.

Note: All functions return the difference in milliseconds!

Link to this section Summary

Functions

Calculates how many milliseconds left until the next day starts.

Calculates how many seconds left until the next hour starts.

Calculates how many milliseconds left until the next interval (hours) will be reached.

Calculates how many milliseconds left until the next minute starts.

Calculates how many milliseconds left until the next interval (minutes) will be reached.

Link to this section Functions

Link to this function

day(relative_to \\ Timex.now())

Calculates how many milliseconds left until the next day starts.

Examples

iex> now = Timex.parse!("2018-10-14T16:48:12.000Z", "{ISO:Extended}")
iex> Every.day(now)  # Time remaining 7h 25m 48s
25_908_000
Link to this function

hour(relative_to \\ Timex.now())

Calculates how many seconds left until the next hour starts.

Examples

iex> now = Timex.parse!("2018-10-14T16:48:12.000Z", "{ISO:Extended}")
iex> Every.hour(now)
708_000
Link to this function

hours(interval, relative_to \\ Timex.now())

Calculates how many milliseconds left until the next interval (hours) will be reached.

Examples

iex> now = Timex.parse!("2018-10-14T16:48:12.000Z", "{ISO:Extended}")
iex> Every.hours(2, now)
4_308_000
Link to this function

minute(relative_to \\ Timex.now())

Calculates how many milliseconds left until the next minute starts.

Examples

iex> now = Timex.parse!("2018-10-14T16:48:12.000Z", "{ISO:Extended}")
iex> Every.minute(now)
48_000
Link to this function

minutes(interval, relative_to \\ Timex.now())

Calculates how many milliseconds left until the next interval (minutes) will be reached.

Examples

iex> now = Timex.parse!("2018-10-14T16:48:12.000Z", "{ISO:Extended}")
iex> Every.minutes(5, now)  # 16:50 > 15:50:00 - 16:48:12
108_000