• sch_jump() shifts a sequence of dates by "jumping" from x to x + jump. After the jump, sch_adjust() is called with the adjustment to ensure that if the new dates are events, they are adjusted to the next available non-event date.

  • sch_step() steps over a sequence of dates 1 day at a time, for n days. After each step, sch_adjust() is called with an adjustment of days(1). This has different results from sch_jump() with a jump of days(n), and is more appropriate for shifting by "n business days".

sch_jump(x, jump, schedule, adjustment = days(1))

sch_step(x, n, schedule)

Arguments

x

[Date]

A vector of dates.

jump

[Period(1) / character(1)]

A lubridate period object, such as lubridate::days() or lubridate::years(). This can also be a character string parsable by lubridate::period(). Sub-daily periods are not allowed.

schedule

[schedule / event]

A schedule or event.

adjustment

[Period(1) / integer(1) / function / formula]

An adjustment to make whenever a date falls on an event.

If this is a lubridate period object, such as lubridate::days(), or an integer, then the adjustment is repeatedly applied as x + adjustment until the next non-event date is found.

If this is a function or formula (i.e., a lambda function), then it should accept 2 arguments, the dates to adjust and the original schedule, and should return a Date vector of the same size as the original input containing the adjusted dates. See the functions on the help page for adj_following() for some examples.

n

[integer(1)]

The number of days to step. Can be negative to step backwards.

Details

For shifting by "n business days", sch_step() is often more appropriate. Imagine you are on a Friday and want to shift forward 2 days using a schedule that marks weekends as events. There are two options:

  • sch_jump() - Jump forward 2 days to Sunday, and apply the adjustment. Assuming adjustment = days(1) was used, that means the result is Monday.

  • sch_step() - Step forward 1 day to Saturday, apply an adjustment of days(1), which rolls forward to Monday. Step forward 1 day to Tuesday, and no further adjustment is required.

The second option more naturally lends itself to business logic. Two business days from Friday is Tuesday.

Examples

# 2019-09-13 is a Friday # Note that here we "jump" to Sunday, then adjust, leaving us on Monday sch_jump("2019-09-13", days(2), on_weekends())
#> [1] "2019-09-16"
# Here we step 1 day to Saturday, adjust to Monday, # then step 1 day to Tuesday sch_step("2019-09-13", 2, on_weekends())
#> [1] "2019-09-17"