tidyverse / lubridate

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

Dates with prefix won't parse without colon #752

Open zkamvar opened 5 years ago

zkamvar commented 5 years ago

I have a situation where we need to build a general system for parsing dates and we are running into the situation where something like "example_data_2019-02-19.xlsx" doesn't correctly parse. I've done some fiddling and figured out that it will parse if there is a colon right before the date.

options(width = 150)

x <- c("example_data_2019-02-19.xlsx",  # fails
       "DOB:12/11/00",  # works
       "example_data:2019-02-19.xlsx", # works 
       "DOB_12/11/00", # fails
       "D12/11/00") # fails

lubridate::guess_formats(x, c("Ymd", "dmy"), print = TRUE)
#>                                     YOmd                          dOmy            Ymd                          dmy           
#> [1,] "example_data_2019-02-19.xlsx" ""                            ""              ""                           ""            
#> [2,] "DOB:12/11/00"                 ""                            "DOB:%d/%Om/%y" ""                           "DOB:%d/%m/%y"
#> [3,] "example_data:2019-02-19.xlsx" "example_data:%Y-%Om-%d.xlsx" ""              "example_data:%Y-%m-%d.xlsx" ""            
#> [4,] "DOB_12/11/00"                 ""                            ""              ""                           ""            
#> [5,] "D12/11/00"                    ""                            ""              ""                           ""
#>                          YOmd                          dOmy                           Ymd                           dmy 
#> "example_data:%Y-%Om-%d.xlsx"               "DOB:%d/%Om/%y"  "example_data:%Y-%m-%d.xlsx"                "DOB:%d/%m/%y"

Created on 2019-02-21 by the reprex package (v0.2.1)

vspinu commented 5 years ago

This is a bug, indeed.