RRule (rrule v0.4.0)
Wrapper functions for interacting with the Rust based rrule library
Link to this section Summary
Functions
Given a RRule, return all occurrences between the given UTC DateTimes.
Given a RRule, return n occurrences between the given UTC DateTimes, where n is the limit
Given a RRule string, return the UTC DateTime when the rule starts
Given a RRule, returns the expanded representation if parsed successfully
Given a RRule, return a boolean indicating if the rule is valid
Link to this section Functions
all_between(string, start_date, end_date)
@spec all_between(String.t(), DateTime.t(), DateTime.t()) :: {:ok, {[DateTime.t()], boolean()}} | {:error, String.t()}
Given a RRule, return all occurrences between the given UTC DateTimes.
In the success case, the return will be {:ok, {occurrences, has_more }}
. The has_more
boolean is used to inform you if there
are more occurrences that weren't returned due to the limits. Generally you'll only care about the occurrences
Note Maximum occurrences is limited to 65,535 to avoid order to prevent infinite loops
example
Example
iex> RRule.all_between("DTSTART:20120101T093000Z\nRRULE:FREQ=DAILY;COUNT=5", ~U[2012-01-01 09:00:00Z], ~U[2012-02-01 09:00:00Z])
{:ok,
{[~U[2012-01-01 09:30:00Z], ~U[2012-01-02 09:30:00Z], ~U[2012-01-03 09:30:00Z],
~U[2012-01-04 09:30:00Z], ~U[2012-01-05 09:30:00Z]], false}}
all_between(RRule_string, start_date, end_date, limit)
@spec all_between(String.t(), DateTime.t(), DateTime.t(), integer()) :: {:ok, {[DateTime.t()], boolean()}} | {:error, String.t()}
Given a RRule, return n occurrences between the given UTC DateTimes, where n is the limit
Note Limit cannot be greater than 65,535
get_start_date(rrule_RRule_string)
@spec get_start_date(String.t()) :: {:ok, DateTime.t()} | {:error, String.t()}
Given a RRule string, return the UTC DateTime when the rule starts
example
Example
iex> RRule.get_start_date("DTSTART:20120101T093000Z\nRRULE:FREQ=DAILY;COUNT=5")
{:ok, ~U[2012-01-01 09:30:00Z]}
parse(RRule_string)
Given a RRule, returns the expanded representation if parsed successfully
example
Example
iex> RRule.parse( "DTSTART:20120101T093000Z\nRRULE:FREQ=DAILY;COUNT=5")
{:ok, "DTSTART:20120101T093000Z\nFREQ=daily;COUNT=5;BYHOUR=9;BYMINUTE=30;BYSECOND=0"}
validate(RRule_string)
Given a RRule, return a boolean indicating if the rule is valid
iex> RRule.validate( "DTSTART:20120101T093000Z\nRRULE:FREQ=DAILY;COUNT=5")
:ok
iex> RRule.validate( "DTSTART:20120101T0930Z\nRRULE:FREQ=DAILY;COUNT=5")
{:error,
"RRule parsing error: `20120101T0930Z` is not a valid datetime format for `DTSTART`."}