Parse dates in format dmy together with dmY using parse_date_time

后端 未结 2 1517

I have a vector of character representation of dates, where formats mostly are dmY (e.g. 27-09-2013), dmy (e.g. 27-09-13), and occasionally some

2条回答
  •  星月不相逢
    2021-01-18 05:10

    It looks like a bug. I am not sure So you should contact the maintainer.

    Building the package source and changing one line in this internal function ( I replace which.max by wich.min):

    .select_formats <-   function(trained){
      n_fmts <- nchar(gsub("[^%]", "", names(trained))) + grepl("%Y", names(trained))*1.5
      names(trained[ which.min(n_fmts) ]) ## replace which.max  by which.min
    }
    

    seems to correct the problem. Frankly I don't know why this works, but I guess it is a kind of ranking..

    parse_date_time(c("27-09-13", "27-09-2013"), orders = c("d m y", "d m Y"))
    [1] "2013-09-27 UTC" "2013-09-27 UTC"
    
    parse_date_time(c("2013-09-27", "13-09-13"), orders = c("Y m d", "y m d"))
    [1] "2013-09-27 UTC" "2013-09-13 UTC"
    

提交回复
热议问题