human_time v0.2.2 HumanTime View Source

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

Creates the time string and raises an exception in case of errors

Generates a single datetime for the string given

Repeats the time string and raises an exception in case of errors

Generates a stream of datetimes for the string given

Link to this section Functions

Link to this function relative!(timestring, opts \\ []) View Source
relative!(String.t(), [term()]) :: DateTime.t()

Creates the time string and raises an exception in case of errors

Link to this function relative(timestring, opts \\ []) View Source
relative(String.t(), [term()]) :: {:ok, DateTime.t()} | {:error, String.t()}

Generates a single datetime for the string given.

Options

from The datetime from when the sequence will be generated, defaults to the current time.

Example

HumanTime.relative("Next wednesday at 1530")

#=> {:ok, #DateTime<2018-08-15 15:30:00.848218Z>}
Link to this function repeating!(timestring, opts \\ []) View Source
repeating!(String.t(), [term()]) :: Enumerable.t()

Repeats the time string and raises an exception in case of errors

Link to this function repeating(timestring, opts \\ []) View Source
repeating(String.t(), [term()]) :: {:ok, Enumerable.t()} | {:error, String.t()}

Generates a stream of datetimes for the string given.

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

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>
#=> ]