lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

3 digit years don't work with parse_date_time

Open kendonB opened this issue 6 years ago • 5 comments

I would expect these to be the same:

lubridate::parse_date_time("999-1-1 00:00:00", orders = c("ymdHMS"))
#> Warning: All formats failed to parse. No formats found.
#> [1] NA
lubridate::parse_date_time("0999-1-1 00:00:00", orders = c("ymdHMS"))
#> [1] "0999-01-01 UTC"

Created on 2019-03-05 by the reprex package (v0.2.1.9000)

kendonB avatar Mar 04 '19 21:03 kendonB

R can do it:

as.POSIXct("999-1-1 00:00:00")
#> [1] "0999-01-01 LMT"

Created on 2019-03-05 by the reprex package (v0.2.1.9000)

kendonB avatar Mar 04 '19 21:03 kendonB

This is hard given current parser's flexibility. One need to choose restrictions, either enforce separators or enforce 2 or 4 digits years. Maybe something could be done in the internal parser. Will have a look.

I will most likely tighten the constraints on the next parser/lubridate rewrite.

vspinu avatar Mar 20 '19 15:03 vspinu

Couldn't you just put 3 digit year with separators as a special case when the a in parser fails?

kendonB avatar Mar 20 '19 19:03 kendonB

I can add a 3 year matcher for the case when separator are present. But the low level parse would still need to understand it, which it current doesn't I will have a look.

vspinu avatar Mar 20 '19 19:03 vspinu

Works with clock:

clock::date_time_parse("999-1-1 00:00:00", "UTC")
#> [1] "0999-01-01 UTC"

Created on 2021-05-25 by the reprex package (v1.0.0)

DavisVaughan avatar May 25 '21 13:05 DavisVaughan