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

Odd parsing failure with lubridate vs strptime for Welsh dates in March #1028

Open stupidpupil opened 2 years ago

stupidpupil commented 2 years ago

For context, "cy" is the ISO 639-1 language code for Cymraeg/Welsh.

Sys.setlocale("LC_TIME", "cy_GB.utf8")
lubridate::ymd("2021-03-19") %>% strftime("%d %B %Y") %>% strptime("%d %B %Y")
# [1] "2021-03-19 GMT"

So far so good, but...

Sys.setlocale("LC_TIME", "cy_GB.utf8")
lubridate::ymd("2021-03-19") %>% strftime("%d %B %Y") %>% lubridate::parse_date_time("%d %B %Y")
# [1] NA
# Warning message:
# All formats failed to parse. No formats found.

# Same result if you try lubridate::fast_strptime("%d %B %Y") or lubridate::dmy()

and more worryingly...

Sys.setlocale("LC_TIME", "cy_GB.utf8")
lubridate::ymd("2021-03-19") %>% strftime("%d %B %Y") %>% lubridate::parse_date_time2("%d %B %Y")
# [1] "2021-05-19 UTC"

# For context:
lubridate::ymd("2021-03-19") %>% strftime("%d %B %Y") 
# [1] "19 Mawrth 2021"
lubridate::ymd("2021-05-19") %>% strftime("%d %B %Y") 
# [1] "19 Mai 2021"

This is using the Ubuntu Welsh language pack:

sudo apt install language-pack-cy
apt show language-pack-cy
# Package: language-pack-cy
# Version: 1:20.04+20210802
# Priority: optional
# Section: translations
# Origin: Ubuntu
# ...
stupidpupil commented 2 years ago

Possibly related to #496 .