View Source HumanTime (human_time v0.3.0)
Human Time is a function to convert a string such as "every other tuesday", "every weekday" or "next friday at 2pm" and convert it into a one or a sequence of date times as allowed by the string.
Link to this section Summary
Functions
Generates a single datetime for the string given.
Creates the time string and raises an exception in case of errors
Generates a stream of datetimes for the string given.
Repeats the time string and raises an exception in case of errors
Link to this section Functions
Specs
relative(String.t(), [term()]) :: {:ok, DateTime.t() | nil} | {:error, String.t()}
Generates a single datetime for the string given.
options
Options
from The datetime from when the sequence will be generated, defaults to the current time.
example
Example
HumanTime.relative("Next wednesday at 1530")
#=> {:ok, #DateTime<2018-08-15 15:30:00.848218Z>}
error-result-is
Error result is:
#=> {:error, message}
Specs
relative!(String.t(), [term()]) :: DateTime.t() | nil
Creates the time string and raises an exception in case of errors
Specs
repeating(String.t(), [term()]) :: {:ok, Enumerable.t()} | {:error, String.t()}
Generates a stream of datetimes for the string given.
options
Options
from The datetime from when the sequence will be generated, defaults to the current time.
until The datetime when the sequence will be terminated, defaults to nil. When nil the sequence will never be terminated.
example
Example
HumanTime.repeating("Every wednesday at 1530")
|> Stream.take(3)
|> Enum.to_list
#=> [
#=> #DateTime<2018-08-15 15:30:00.848218Z>,
#=> #DateTime<2018-08-22 15:30:00.848218Z>,
#=> #DateTime<2018-08-29 15:30:00.848218Z>
#=> ]
error-result-is
Error result is:
Specs
repeating!(String.t(), [term()]) :: Enumerable.t()
Repeats the time string and raises an exception in case of errors