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

Milliseconds separator #1099

Closed Dimeruben closed 1 year ago

Dimeruben commented 1 year ago

Hello,

First, thank you for the great package!

I would like to suggest if it would be possible to also accept ":" as a separator for milliseconds as some devices provide it with that format.

04/10/2021 17:49:02:195 VS 04/10/2021 17:49:02.195

I change the format manually easily, but maybe it would be nice to add it in a new version if the change is not very difficult to implement...

Thank you very much!

vspinu commented 1 year ago

This is new to me. Where is this format used more concretely? It's not very common I would presume, or is it?

Dimeruben commented 1 year ago

Thank you for the response. In my case, I found that format in "Agilent-Keysight" dataloggers which are used for precision measurements in research laboratories. I don't know if that format is shared with other devices, as I have worked only with this brand.

vspinu commented 1 year ago

I am inclined not to address this issue explicitly for the time being. Mostly because of the backward compatibility. If we start parsing seconds with : it would break existing usecases where second is followed by : for whatever reason.

I would suggest a simple workaround for now to just replace : with . like this:

> sub(":([^:]+)$", ".\\1", "04/10/2021 17:49:02:195")
[1] "04/10/2021 17:49:02.195"
> gsub(":", ".", "04/10/2021 17:49:02:195")
[1] "04/10/2021 17.49.02.195"

Both formats are understood by dmy_hms.

When we will finally extract the parser from lubridate we should probably add a parameter like milisecond_secparator to account for such cases.