tidyverse / lubridate

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

Parsing oddity with ymd_hms #552

Open raymondben opened 7 years ago

raymondben commented 7 years ago

ymd_hms("2007-03-08 13:13",truncated=1) gives "2007-03-08 13:13:00 UTC", as expected. ymd_hms("2007-03-08 1:13") gives NA and warning, as expected. But ymd_hms("2007-03-08 13:13") gives "2020-07-03 08:13:13 UTC" without warning. It is using a "YYMM-DD-HH MM:SS" date format. Maybe this is expected behaviour, but allowing that liberal a date format (specifically "-" as a separator both within the date and between the DD and HH) seems likely to lead to parsing results that the user did not expect.

(with lubridate_1.6.0 and lubridate_1.6.0.9009)

vspinu commented 7 years ago

Hm. That's indeed odd. Thanks for catching this.

vspinu commented 6 years ago

You are right, it's sort of an expected behavior :( You are also right that the parser is too liberal. I regretted making it as such many, many times so far. But well, now it's a bit too late. Fixing this one would almost surely break some more rare patterns.

The new stand-alone parser (which is slowly in the making) won't have this problem.

hadley commented 4 years ago

Minimal reprex:

library(lubridate, warn.conflicts = FALSE)

ymd_hms("2007-03-08 13:13")
#> [1] "2020-07-03 08:13:13 UTC"
ymd_hms("2007-03-08 1:13")
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

Created on 2019-11-19 by the reprex package (v0.3.0)