time_point_shift()
shifts x
to the target
weekday. You can
shift to the next or previous weekday. If x
is currently on the target
weekday, you can choose to leave it alone or advance it to the next instance
of the target
.
Weekday shifting is one of the easiest ways to floor by week while
controlling what is considered the first day of the week. You can also
accomplish this with the origin
argument of time_point_floor()
, but
this is slightly easier.
time_point_shift(x, target, ..., which = "next", boundary = "keep")
x 
A time point. 

target 
A weekday created from Generally this is length 1, but can also be the same length as 
...  These dots are for future extensions and must be empty. 
which 
One of:

boundary 
One of:

x
shifted to the target
weekday.
#> <weekday[2]> #> [1] Tue Wed#> <time_point<naive><day>[2]> #> [1] "20190107" "20190107"# Shift to the previous Monday # This is an easy way to "floor by week" with a target weekday in mind time_point_shift(x, monday, which = "previous")#> <time_point<naive><day>[2]> #> [1] "20181231" "20181231"# What about Tuesday? tuesday < weekday(clock_weekdays$tuesday) # Notice that the day that was currently on a Tuesday was not shifted time_point_shift(x, tuesday)#> <time_point<naive><day>[2]> #> [1] "20190101" "20190108"# You can force it to `"advance"` time_point_shift(x, tuesday, boundary = "advance")#> <time_point<naive><day>[2]> #> [1] "20190108" "20190108"