/
date.R
47 lines (39 loc) · 1.23 KB
/
date.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#' Specify the date(s) of a schedule
#'
#' @description
#' Creates a schedule of events occurring on the dates specified.
#'
#' This function is best used when making ad-hoc changes to other schedules.
#'
#' @param ... A vector of dates.
#'
#' @keywords date, schedule
#' @return A schedule object.
#' @examples
#' my_dates <- seq.Date(as.Date("2000-01-01"),
#' as.Date("2000-01-05"),
#' "1 day")
#'
#' on_first_day_millennium <- on_date(as.Date("2000-01-01"))
#' on_first_or_second_day_millennium <- on_date(as.Date("2000-01-01"),
#' as.Date("2000-01-02"))
#'
#' happen(on_first_day_millennium, my_dates)
#' happen(on_first_or_second_day_millennium, my_dates)
#'
#' on_regular_paydays <- on_mday(25)
#' on_bonus_payday <- on_date(as.Date("2000-12-20"))
#'
#' on_paydays <- also_occur(on_bonus_payday, on_regular_paydays)
#'
#' schedule_days(on_paydays, during = 2000)
#' @export
on_date <- function(...){
x <- unlist(list(...))
if(length(x) > 1) return(check_vec_loop(x, on_date))
out <- make_element(x, identity)
class(out) <- "schedule"
attr(out, "earliest_date") <- lubridate::as_date(x)
attr(out, "latest_date") <- lubridate::as_date(x)
out
}