Creates a schedule of events occuring on the specified days of certain periods.
The type of period (week, month, quarter, year) is determined by the function used (see Details section).
on_mday(...) on_yday(...) on_qday(...) on_wday(..., week_start = getOption("lubridate.week.start", 7)) on_weekend() on_weekday()
... | A numeric vector of day specifications. In the case of |
---|---|
week_start | If using the |
A schedule object.
Each function creates a schedule where the events occur only on the specified days within the given period:
on_mday
for days of the month. Eg:
on_mday(1)
for the 1st day of each month.
on_mday(15)
for the 15th day of each month.
on_mday(31)
for the 31st day of each month (where that exists).
on_yday
for days of the year. Eg:
on_yday(1)
for the 1st day of each year.
on_yday(300)
for the 300th day of each year.
on_yday(366)
for the 366th day of each year (where that exists).
on_qday
for days in the quarter. Eg:
on_qday(1)
for the 1st day of every quarter.
on_qday(45)
for the 45th day of every quarter.
on_qday(92)
for the 92nd day of every quarter (where that exists).
on_wday
for days of the week.
These can be specified using numbers (where by default 1 is Sunday, see the Arguments section above.)
on_wday(1)
for Sundays (by default).
on_wday(7)
for Saturdays (by default).
Or using weekday names:
on_wday("Sunday")
for Sundays.
on_wday("Saturday")
for Saturdays.
on_wday("Wednesday")
for Wednesdays.
Or their abbreviations:
on_wday("Sun")
for Sundays.
on_wday("Sat")
for Saturdays.
on_wday("Wed")
for Wednesdays.
All functions accept multiple day elements in a single call. For example
on_mday(7, 9)
produces a schedule of dates occuring on the 7th and 9th
days of every month. Likewise on_mday(1:5)
produces a schedule of dates
occuring on the first five days of every month. Similarly
on_wday("Tue", "Thu")
produces a schedule of events occuring every
week on both Tuesdays and Thursdays.
on_weekend()
is a convenience function for
on_wday("Sat", "Sun")
. on_weekday()
is a convenience function for
dont_occur(on_wday("Sat", "Sun"))
.
my_dates <- seq.Date(from = as.Date("2000-01-01"), to = as.Date("2000-12-01"), by = "1 month") happen(on_mday(1), my_dates)#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE#> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE#> [1] TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE#> [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE#> [1] FALSE TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE#> [1] TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE#> [1] FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE## Invalid inputs will produce an immediate error:# NOT RUN { on_mday(32) on_wday(8) # }