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

Use explicit integers in `year()` and `month()` #1103

Open malcolmbarrett opened 1 year ago

malcolmbarrett commented 1 year ago

An astute student pointed out to use that day(), year() and month() are inconsistent in their return types:

library(lubridate)
x <- ymd("2012-03-26")
is.integer(month(x))
#> [1] FALSE
is.integer(day(x))
#> [1] TRUE
is.integer(year(x))
#> [1] FALSE

Created on 2022-12-15 with reprex v2.0.2

This seems like an unintentional conversion due to addition. This PR uses explicit integer addition to have month() and year() return integers

vspinu commented 1 year ago

This has been attempted before The consequences are not as benign as they might appear.

Let's try to give it another try, but not for the forthcoming release (end of this month) but for the next one. leaving this open till then.

malcolmbarrett commented 1 year ago

Sounds good. Happy to help with revdep fallout when the time comes. Just let me know