until_then v0.0.1 UntilThen
This library tells you how many milliseconds to the next occurrence of a
scheduled event. This is very convenient to combine with :timer.sleep/1
or
Process.send_after/3
as a means of repeatedly invoking some code on a
schedule and not having those invocations drift.
Summary
Functions
This function is the primary interface of this module. You can call it anytime you need to know the delay until the next occurrence of a scheduled event
This is just like UntilThen.next_occurrence/2
, save that you also pass a
Calendar.DateTime
to be used as the point from
which the next occurrence
is calculated. This is the pure function that powers the calculation and is
used to test it, but it’s generally more convenient to work with the impure
wrapper in your own code. However, you could use this function to vary time
zones across calls, if needed
This function returns the time zone assumed for string times passed into
UntilThen.next_occurrence/2
. It defaults to "UTC"
but it can be
configured
Types
day ::
:monday |
:tuesday |
:wednesday |
:thursday |
:friday |
:saturday |
:sunday |
:weekdays
An atom that is a named day of the week or the special flag :weekdays
.
Functions
This function is the primary interface of this module. You can call it anytime you need to know the delay until the next occurrence of a scheduled event.
You pass this function a day name (like :tuesday
) or the special flag
:weekdays
followed by a time string in the 24-hour format HH:MM:SS (like
"13:45:00"
). It will return the number of milliseconds to the next
occurrence of the indicated day and time.
An example usage could be:
defmodule WeekdayCheckins do
def run_checkins do
UntilThen.next_occurrence(:weekdays, "12:00:00") |> :timer.sleep
checkin
run_checkins
end
def checkin do
# do the work here...
end
end
Specs
This is just like UntilThen.next_occurrence/2
, save that you also pass a
Calendar.DateTime
to be used as the point from
which the next occurrence
is calculated. This is the pure function that powers the calculation and is
used to test it, but it’s generally more convenient to work with the impure
wrapper in your own code. However, you could use this function to vary time
zones across calls, if needed.
Specs
scheduled_time_zone :: String.t
This function returns the time zone assumed for string times passed into
UntilThen.next_occurrence/2
. It defaults to "UTC"
but it can be
configured:
config :until_then, scheduled_time_zone: "US/Pacific"