# A Saturday
x <- as.Date("1970-01-03")
on_weekends <- weekly() %>% recur_on_weekends()
# Adjust forward to Monday
adj_following(x, on_weekends)
# Adjust backwards to Friday
adj_preceding(x, on_weekends)
# Adjust to nearest non-event date
adj_nearest(x, on_weekends)
adj_nearest(x + 1, on_weekends)
# Sundays, one of which is at the end of the month
sundays <- as.Date(c("2020-05-24", "2020-05-31"))
# Adjust forward, unless that takes us into a new month, in which case we
# adjust backwards.
adj_modified_following(sundays, on_weekends)
# Saturdays, one of which is at the beginning of the month
saturdays <- as.Date(c("2020-08-01", "2020-08-08"))
# Adjust backwards, unless that takes us into a new month, in which
# case we adjust forwards
adj_modified_preceding(saturdays, on_weekends)
Run the code above in your browser using DataLab