RRule

A library to manage recurrence rules following the standards from RFC-5547.

How to use it

To define a recurrence rule, start by creating the desired frequency rule definition:

rust let daily = Frequency::Daily { interval: 1, by_time: vec![], };

Then, create a Recurrence with the frequency defined:

rust ... let recurrence = Recurrence::new( daily, Utc::now(), // start date Some(Utc::now() + Duration::days(1)), // end date Some(Duration::hours(1)), // duration (optional );

The Recurrence struct is an iterator that will yield all the dates that match the recurrence rules defined.

You can then use the Recurrence as an iterator by looping over it or collecting the results into a Vec

```rust ... for event in recurrence { ... }

or

let events: Vec> = recurrence.collect(); ```

The end attribute of a Recurrence is optional, and if not specified, it will yield events until the MAX_DATE.

The MAX_DATE is defined as 9999-12-31T23:59:59Z

The duration attribute of a Recurrence is optional, and if not specified, it will use the default as 1 hour Duration::hours(1).

Supported frequencies

Current supporting recurrence rules:

Secondly Frequencies

Represents the rules for a recurrence that happens every x seconds.

```rust use rrules::Frequency;

let every_second = Frequency::Secondly { interval: 1, };

let every5seconds = Frequency::Secondly { interval: 5, }; ```

Minutely Frequencies

Represents the rules for a recurrence that happens every x minutes.

```rust use rrules::Frequency;

let every_minute = Frequency::Minutely { interval: 1, };

let every5minutes = Frequency::Minutely { interval: 5, }; ```

Hourly Frequencies

Represents the rules for a recurrence that happens every x hours.

```rust use rrules::Frequency;

let every_hour = Frequency::Hourly { interval: 1, };

let every6hours = Frequency::Hourly { interval: 6, }; ```

Daily Frequencies

Represents the rules for a recurrence that happens x times every x days.

```rust use chrono::{DateTime, Duration, Utc}; use rrules::{Frequency, Time};

let daily = Frequency::Daily { interval: 1, by_time: vec![], };

let every3days = Frequency::Daily { interval: 3, by_time: vec![], };

let everydayat8am = Frequency::Daily { interval: 1, bytime: vec![ Time::from_str("08:00:00").unwrap(), ] }; ```

Weekly Frequencies

Represents the rules for a recurrence that happens x times every x weeks.

```rust let weekly = Frequency::Weekly { interval: 1, by_day: vec![], };

let twiceaweek = Frequency::Weekly { interval: 1, by_day: vec![Weekday::Mon, Weekday::Tue], }; ```

Monthly Frequencies

Represents the rules for a recurrence that happens x times every x months.

rust let monthly = Frequency::Monthly { interval: 1, by_month_day: vec![], nth_weekdays: vec![], };

Monthly by month day

When specifying by_month_day, it will only yield the dates that match the days of the month specified.

rust let every_15th = Frequency::Monthly { interval: 1, by_month_day: vec![15], nth_weekdays: vec![], };

Monthly by nth day

When specifying nth_weekdays, it will only yield the dates that match the nth days of the week specified. I.g. if you want to have a recurrence every first Monday of the month, you can do:

rust let every_first_monday = Frequency::Monthly { interval: 1, by_month_day: vec![], nth_weekdays: vec![ NthWeekday::new(Weekday::Mon, 1), ] };

Yearly Frequencies

Represents the rules for a recurrence that happens x times every x years.

rust let yearly = Frequency::Yearly { interval: 1, by_month_date: vec![], };

Yearly by month day

When specifying by_month_date, it will only yield the dates that match the days of the month specified. E.g. if you want to have a recurrence every 15th January of the year, you can do:

rust let every_15th_january = Frequency::Yearly { interval: 1, by_month_date: vec![ MonthlyDate::new(Month::January, 15), ] };