Lubridate::round_date() does not accept date

Viewed 14

I'm learning R package lubridate. I discovered that the round_date() function does not provide correct answer when the input is a date. It has to 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"

Is it a design feature or a feature defect?

0 Answers
Related