A generic function for rounding date and time values
Arguments
- x
A vector of class POSIX or Date.
- n
Unit to round to. Defaults to mins. Numeric values treated as seconds. Otherwise this should be one of "mins", "hours", "days", "weeks", "months", "years" (plural optional).
- tz
Time zone to be used, defaults to "UTC" (Twitter default)
Examples
## class posixct
round_time(Sys.time(), "12 hours")
#> [1] "2023-05-28 UTC"
## class date
unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))
#> [1] "2023-05-25" "2023-06-01" "2023-06-08" "2023-06-15" "2023-06-22"
#> [6] "2023-06-29" "2023-07-06" "2023-07-13" "2023-07-20" "2023-07-27"
#> [11] "2023-08-03" "2023-08-10" "2023-08-17" "2023-08-24" "2023-08-31"