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

ymd_hms() function left-pads some dates that have missing "seconds" values #1151

Open mgimond opened 7 months ago

mgimond commented 7 months ago

The ymd_hms function will left-pad date strings that are missing "seconds" values with "20". This only happens for some dates--can't seem to find a pattern.

library(lubridate)

# Generates NA, as expected
ymd_hms("2020-12-22 33:33") 
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

# Generates incorrect dates by left padding with "20"
ymd_hms("1901-12-22 12:33")
#> [1] "2019-01-12 22:12:33 UTC"

ymd_hms("2002-12-22 33:33")
#> [1] "2020-02-12 22:33:33 UTC"

ymd_hms("1801-12-22 12:33")
#> [1] "2018-01-12 22:12:33 UTC"

Created on 2024-01-05 with reprex v2.0.2