posixt-shifting | R Documentation |
date_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
.
Shifting with date-times retains the time of day where possible. Be aware that you can run into daylight saving time issues if you shift into a daylight saving time gap or fallback period.
## S3 method for class 'POSIXt'
date_shift(
x,
target,
...,
which = "next",
boundary = "keep",
nonexistent = NULL,
ambiguous = x
)
x |
A date-time vector. |
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:
|
nonexistent |
One of the following nonexistent time resolution strategies, allowed to be either length 1, or the same length as the input:
Using either If If |
ambiguous |
One of the following ambiguous time resolution strategies, allowed to be either length 1, or the same length as the input:
Alternatively, Finally, If If |
x
shifted to the target
weekday.
tuesday <- weekday(clock_weekdays$tuesday)
x <- as.POSIXct("1970-04-22 02:30:00", "America/New_York")
# Shift to the next Tuesday
date_shift(x, tuesday)
# Be aware that you can run into daylight saving time issues!
# Here we shift directly into a daylight saving time gap
# from 01:59:59 -> 03:00:00
sunday <- weekday(clock_weekdays$sunday)
try(date_shift(x, sunday))
# You can resolve this with the `nonexistent` argument
date_shift(x, sunday, nonexistent = "roll-forward")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.