| 1 | <h1 align="center">RRule.rs</h1> |
| 2 | <p align="center">A pure and efficient Rust implementation of recurrence rules as defined in the iCalendar RFC.</p> |
| 3 | <p align="center"> |
| 4 | <a href="https://codecov.io/gh/fmeringdal/rust-rrule"> |
| 5 | <img src="https://codecov.io/gh/fmeringdal/rust-rrule/branch/main/graph/badge.svg?token=UneXhtuXWo"/> |
| 6 | </a> |
| 7 | <a href="https://crates.io/crates/rrule"><img src="https://img.shields.io/crates/v/rrule.svg" /></a> |
| 8 | <a href="https://docs.rs/rrule/latest/rrule/"><img src="https://img.shields.io/badge/docs-rrule-blue" /></a> |
| 9 | </p> |
| 10 | |
| 11 | ## Specification |
| 12 | |
| 13 | This crate follows the [iCalendar (RFC-5545) specification][ical_spec] for the "Recurrence Rule". |
| 14 | The Recurrence Rule spec corresponds to the `RRule` object in this crate. |
| 15 | In addition, it allows for adding the ["DTSTART" property][dtstart_property] separated by a newline. |
| 16 | |
| 17 | The crate allows for a "BYEASTER" filter. But this is opt-in with the feature flag `"by-easter"`. |
| 18 | |
| 19 | ### RRuleSet |
| 20 | |
| 21 | `RRuleSet` allows for a combination for `RRule`s and some other properties. |
| 22 | |
| 23 | - List of [RRules](https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html): |
| 24 | Allows multiple RRules to be combined. (Union, `A ∪ B`) |
| 25 | - List of [RDates](https://icalendar.org/iCalendar-RFC-5545/3-8-5-2-recurrence-date-times.html): |
| 26 | A list of datetime combinations to always include. (Union, `A ∪ B`) |
| 27 | - List of [ExRule](https://datatracker.ietf.org/doc/html/rfc2445#section-4.8.5.2) (see note below): |
| 28 | Allows of RRules that are removed from the results. (Complement `A \ B` or `A - B`) |
| 29 | - List of [ExDate](https://icalendar.org/iCalendar-RFC-5545/3-8-5-1-exception-date-times.html): |
| 30 | A list of datetime combinations to always exclude. (Complement `A \ B` or `A - B`) |
| 31 | |
| 32 | Note: "EXRULE" was originally part of [RFC 2445](https://datatracker.ietf.org/doc/html/rfc2445#section-4.8.5.2), |
| 33 | [RFC 5545][ical_spec] obsoletes this specification. |
| 34 | But "EXRULE" works exactly the same als "RRULE" except that it excludes dates. You can enable "EXRULE" by enabling the "exrule" feature flag which is disabled by default. |
| 35 | |
| 36 | If you notice that the implementation differs from the specifications above, please open an issue. |
| 37 | |
| 38 | ## Library Usage |
| 39 | |
| 40 | ```rust |
| 41 | use rrule::RRuleSet; |
| 42 | |
| 43 | // RRule that starts 2012.02.01 and occurs daily for 3 days. |
| 44 | let rrule: RRuleSet = "DTSTART:20120201T093000Z\nRRULE:FREQ=DAILY;COUNT=3".parse().unwrap(); |
| 45 | |
| 46 | // Set hard limit in case of infinitely recurring rules. |
| 47 | let limit = 100; |
| 48 | // Get all recurrences of the rrule |
| 49 | let result = rrule.all(limit); |
| 50 | assert_eq!(result.dates.len(), 3); |
| 51 | ``` |
| 52 | |
| 53 | See more examples at [docs.rs](https://docs.rs/rrule) |
| 54 | |
| 55 | ## Command Line Tool Usage |
| 56 | |
| 57 | Install the command line tool with: |
| 58 | |
| 59 | ```bash |
| 60 | cargo install rrule --features="cli-tool" |
| 61 | ``` |
| 62 | |
| 63 | Then run it with: |
| 64 | |
| 65 | ```bash |
| 66 | rrule "DTSTART:20120201T093000Z\nRRULE:FREQ=DAILY;COUNT=3" |
| 67 | ``` |
| 68 | |
| 69 | ## Security |
| 70 | |
| 71 | You should read the [security docs](https://github.com/fmeringdal/rust-rrule/blob/main/SECURITY.md) if you use arbitrary inputs from users for constructing the recurrence rules. |
| 72 | |
| 73 | ## Limitation and limits |
| 74 | |
| 75 | All dates are limited to the range or years +/-262_000[^1] because of [Chrono][chrono] limits. |
| 76 | See [Chrono's limits for more info](https://github.com/chronotope/chrono#limitations). |
| 77 | |
| 78 | Supported timezones are limited to by the timezones that [Chrono-Tz][chrono-tz] supports. |
| 79 | This is equivalent to the IANA database. |
| 80 | See [Chrono-Tz's limits for more info](https://github.com/chronotope/chrono-tz/#limiting-the-timezone-table-to-zones-of-interest). |
| 81 | |
| 82 | ### Validation Limits |
| 83 | |
| 84 | <a name="validation_limits"></a> |
| 85 | Because the specifications do give a lot of flexibilities this can be [abused very easily](#Security). |
| 86 | In order to prevent most of the abuse we've imposed arbitrary limitation when on the `RRuleSet::all` |
| 87 | method. The validation limits aren't enforced for the `RRuleSet::all_unchecked` method or when |
| 88 | using the `Iterator` api directly. |
| 89 | |
| 90 | Limitations: |
| 91 | | Description | Arbitrary Limit | Crate Limit | |
| 92 | |----------------------------------|-----------------------|-----------------------------| |
| 93 | | Year range | -10_000..=10_000 | -262_000..=262_000 (Chrono) | |
| 94 | | Max interval with freq Yearly | 10_000 (10000 years) | 65_535 (u16::MAX) | |
| 95 | | Max interval with freq Monthly | 1_000 (~83 years) | 65_535 (u16::MAX) | |
| 96 | | Max interval with freq Weekly | 1_000 (~19 years) | 65_535 (u16::MAX) | |
| 97 | | Max interval with freq Daily | 10_000 (~27 years) | 65_535 (u16::MAX) | |
| 98 | | Max interval with freq Hourly | 10_000 (~416 days) | 65_535 (u16::MAX) | |
| 99 | | Max interval with freq Minutely | 10_000 (~7 days) | 65_535 (u16::MAX) | |
| 100 | | Max interval with freq Secondly | 50_000 (~13 hours) | 65_535 (u16::MAX) | |
| 101 | | Iteration limit | 100_000 | 4_294_967_295 (u32::MAX) | |
| 102 | |
| 103 | By default, the "Arbitrary Limit" is used. If you instead want to use the "Crate Limit". |
| 104 | Make sure you [understand the risks that come with this](#safety). |
| 105 | |
| 106 | ## Inspired by |
| 107 | |
| 108 | - [python-dateutil library](http://labix.org/python-dateutil/) |
| 109 | - [rrule.js](https://github.com/jakubroztocil/rrule) |
| 110 | |
| 111 | ## License |
| 112 | |
| 113 | The code in this project is licensed under the [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE) license. |
| 114 | |
| 115 | All contributions to this project will be similarly licensed. |
| 116 | |
| 117 | [chrono]: https://github.com/chronotope/chrono |
| 118 | [chrono-tz]: https://github.com/chronotope/chrono-tz/ |
| 119 | [ical_spec]: https://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html |
| 120 | [dtstart_property]: https://icalendar.org/iCalendar-RFC-5545/3-8-2-4-date-time-start.html |
| 121 | |
| 122 | [^1]: See [validation limits](#validation_limits) sections more info. |