tidyverse / lubridate

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

Trailing zeroes in quarter-year parsing now fail to parse #1091

Closed paleolimbot closed 1 year ago

paleolimbot commented 1 year ago

After the latest release we started getting some test failures in the Arrow R package ( https://github.com/apache/arrow/pull/14615 )...is this intended behaviour? It is a little odd, since the trailing zero on 1.2020 could easily get dropped.

In the previous lubridate:

lubridate::parse_date_time(c(3.2007, 2.1970, 1.2020, 4.2009, 1.1975, NA), "qY")
#> [1] "2007-07-01 UTC" "1970-04-01 UTC" "2020-01-01 UTC" "2009-10-01 UTC"
#> [5] "1975-01-01 UTC" NA

In latest lubridate:

lubridate::parse_date_time(c(3.2007, 2.1970, 1.2020, 4.2009, 1.1975, NA), "qY")
#> Warning: 2 failed to parse.
#> [1] "2007-07-01 UTC" NA               NA               "2009-10-01 UTC"
#> [5] "1975-01-01 UTC" NA
vspinu commented 1 year ago

Thanks for bringing it up! It's a use case which wasn't considered and covered in tests.

Your example relies on the formatting behavior of our internal conversion to character, which is not full proof of course:

## this works
> format(c(3.2007, 2.1970, 1.2020))
[1] "3.2007" "2.1970" "1.2020"
## but this does not
> format(c(2.1970, 1.2020))
[1] "2.197" "1.202"