I'm learning the R package lubridate. I discovered that the round_date()
function does not provide the correct answer when the input is a date. The input must be a datetime. floor_date()
and ceiling_date()
have no such problem.
For example,
date1 <- as_datetime("2022-09-23")
date2 <- as_datetime("2022-05-19")
round_date(date1, "year")
#> [1] "2023-01-01 UTC"
round_date(date2, "year")
#> [1] "2022-01-01 UTC"
date3 <- as_date("2022-09-23")
date4 <- as_date("2022-05-19")
round_date(date3, "year")
#> [1] "2022-01-01"
round_date(date4, "year")
#> [1] "2022-01-01"
What gives? Do I miss out something?