rrule: Create a recurrence rule

View source: R/rrule.R

rruleR Documentation

Create a recurrence rule

Description

These functions allow you to create a recurrence rule with a specified frequency. They are the base elements for all recurrence rules. To add to them, use one of the ⁠recur_*()⁠ functions.

  • daily() Recur on a daily frequency.

  • weekly() Recur on a weekly frequency.

  • monthly() Recur on a monthly frequency.

  • yearly() Recur on a yearly frequency.

Usage

daily(since = NULL, until = NULL)

weekly(since = NULL, until = NULL)

monthly(since = NULL, until = NULL)

yearly(since = NULL, until = NULL)

Arguments

since

⁠[Date(1)]⁠

The lower bound on the event set. Depending on the final recurrence rule, pieces of information from this anchor date might be used to generate a complete recurrence rule.

until

⁠[Date(1)]⁠

The upper bound on the event set.

Details

By default, since == "1900-01-01" and until == "2100-01-01", which should capture most use cases well while still being performant. You may need to adjust these dates if you want events outside this range. See almanac_since() and almanac_until() for more information.

In terms of speed, it is generally more efficient if you adjust the since and until date to be closer to the first date in the sequence of dates that you are working with. For example, if you are working with dates in the range of 2019 and forward, adjust the since date to be 2019-01-01 for a significant speed boost.

As the anchor date, events are often calculated relative to this date. As an example, a rule of "on Monday, every other week" would use the since date to find the first Monday to start the recurrence from.

There is no quarterly() recurrence frequency, but this can be accomplished with monthly() %>% recur_on_interval(3). The month to start the quarterly interval from will be pulled from the since date inside monthly(). The default will use a quarterly rule starting in January since the default since date is 1900-01-01. See the examples.

Value

A new empty rrule.

Examples

rrule <- monthly() %>% recur_on_day_of_month(25)

alma_search("1970-01-01", "1971-01-01", rrule)

# Notice that dates before 1900-01-01 are never generated with the defaults!
alma_search("1899-01-01", "1901-01-01", rrule)

# Adjust the `since` date to get access to these dates
rrule_pre_1900 <- monthly(since = "1850-01-01") %>% recur_on_day_of_month(25)
alma_search("1899-01-01", "1901-01-01", rrule_pre_1900)

# A quarterly recurrence rule can be built from
# `monthly()` and `recur_on_interval()`
on_first_of_the_quarter <- monthly() %>%
  recur_on_interval(3) %>%
  recur_on_day_of_month(1)

alma_search("1999-01-01", "2000-04-01", on_first_of_the_quarter)

# Alter the starting quarter by altering the `since` date
on_first_of_the_quarter_starting_in_feb <- monthly(since = "1998-02-01") %>%
  recur_on_interval(3) %>%
  recur_on_day_of_month(1)

alma_search(
  "1999-01-01",
  "2000-04-01",
  on_first_of_the_quarter_starting_in_feb
)


almanac documentation built on April 14, 2023, 12:23 a.m.