lubridate
lubridate copied to clipboard
3 digit years don't work with parse_date_time
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)
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)
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.
Couldn't you just put 3 digit year with separators as a special case when the a in parser fails?
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.
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)