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

Parsing days in text form does not fail, but uses part of the year as day #1084

Closed Cecca closed 1 year ago

Cecca commented 1 year ago

Using the mdy function to parse strings into date values may result in wrong dates when the day number is provided as text. For instance, in the snippet below I would expect the string to either be parsed as "2022-11-03" or to be coerced to NA.

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
mdy("November third, 2022")
#> [1] "2022-11-20"

Created on 2022-11-03 by the reprex package (v2.0.1)

What happens instead is that, apparently, the string "third" is ignored, and the first two digits of the year are used as the day.

vspinu commented 1 year ago

Yes, third is not supported. Thus 2022 is parsed as short year and day 10. There is #1077 open to address this case.