Given a schedule of events, create a new schedule of only the nth occurrences within a given period.
on_nth(n, x, within_given) on_first(x, within_given) on_second(x, within_given) on_third(x, within_given) on_fourth(x, within_given) on_last(x, within_given)
n | A single integer specifying which event to select. A negative
integer will select the nth last event (i.e. |
---|---|
x | A schedule from which to select events. |
within_given | A period from within which to select events. Can be either:
|
A schedule object.
Convenience functions are provided for the first, second, third, fourth and last events of a given period.
All functions accept arbitrarily complex schedules. For example, if you
wanted a schedule of events occurring on the 12th either Tuesday or Thursday
of the quarter you would use:
on_nth(12, on_wday("Tue", "Thu"), within_given = "quarter")
.
tuesday <- on_wday("Tue") second_tuesday_month <- on_second(tuesday, within_given = "month") schedule_days(second_tuesday_month, during = 2000)#> [1] "2000-01-11" "2000-02-08" "2000-03-14" "2000-04-11" "2000-05-09" #> [6] "2000-06-13" "2000-07-11" "2000-08-08" "2000-09-12" "2000-10-10" #> [11] "2000-11-14" "2000-12-12"last_tuesday_year <- on_last(tuesday, within_given = "year") schedule_days(last_tuesday_year, during = 2000)#> [1] "2000-12-26"tenth_tuesday_quarter <- on_nth(10, tuesday, within_given = "quarter") schedule_days(tenth_tuesday_quarter, during = 2000)#> [1] "2000-03-07" "2000-06-06" "2000-09-05" "2000-12-05"tues_or_thurs <- on_wday("Tue", "Thu") tenth_tues_or_thurs_quarter <- on_nth(10, tues_or_thurs, within_given = "quarter") schedule_days(tenth_tues_or_thurs_quarter, during = 2000)#> [1] "2000-02-03" "2000-05-04" "2000-08-03" "2000-11-02"