tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
728 stars 207 forks source link

ceiling_date returns date with year off-by-one for dates prior to 1970 #1107

Closed groditi closed 1 year ago

groditi commented 1 year ago

For dates before 1970 ceiling_months will return the incorrect year if change_on_boundary = FALSE

 ceiling_date(
     c(ymd('1969-01-01')+years(c(0:2))),
     unit = 'month', 
     change_on_boundary = FALSE
 )
#[1] "1968-02-01" "1969-02-01" "1971-01-01"
 ceiling_date(
     c(ymd('1969-01-01')+years(c(0:2))),
     unit = 'month', 
     change_on_boundary = TRUE
 )
#[1] "1969-02-01" "1970-02-01" "1971-02-01"
vspinu commented 1 year ago

Works fine for me with devel on linux. Which version of lubridate and timechange do you have?

> ceiling_date(
+      c(ymd('1969-01-01')+years(c(0:2))),
+      unit = 'month', 
+      change_on_boundary = FALSE
+ )
[1] "1969-01-01" "1970-01-01" "1971-01-01"
> ceiling_date(
+      c(ymd('1969-01-01')+years(c(0:2))),
+      unit = 'month', 
+      change_on_boundary = TRUE
+ )
[1] "1969-02-01" "1970-02-01" "1971-02-01"
vspinu commented 1 year ago

I have just added this test case to our unit tests and it works as expected in the CI on all platforms and versions of R. So it's pretty surely fixed in devel. Please reopen if you keep seeing this. The new CRAN release is coming soon.

groditi commented 1 year ago

Lubridate 1.8.0 on windows, no version of timechange installed. Installed 1.9.2 from source and timechange 0.2.0 from source and that fixed it