as.POSIXct
appears to be mishandling timestamps where there is a leading 0 in the milliseconds part of the string, such as ".043"
time_043_millis <- "20210909-20:05:10.043" #doesnt work
time_143_millis <- "20210909-20:05:10.143" #works
When converting a timestamp ending with ".043" milliseconds , result is wrong
as.POSIXct(time_043_millis, format = "%Y%m%d-%H:%M:%S.%OS")
#Returns:
#[1] "2021-09-09 20:05:43 AEST"
# its messed up, the seconds portion should be 10, and the 43 milliseconds as a fraction of a second, but its taken 43 to be seconds portion??
When converting a timestamp ending with ".143" milliseconds, result is correct.
as.POSIXct(time_143_millis, format = "%Y%m%d-%H:%M:%S.%OS")
#Returns:
#[1] "2021-09-09 20:05:10 AEST"
# This time its working correctly.. why??
I've tested this same behavior occurs on a windows system, and a linux system.
Is there some explanation for this?
Is this a bug?
R Session infos from both Linux and windows systems are included in the below code block...
Thanks in advance.
#Windows System
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] colorspace_1.4-1 scales_1.1.1 compiler_4.0.2 R6_2.4.1 tools_4.0.2 tinytex_0.29
[7] xfun_0.21 lifecycle_0.2.0 munsell_0.5.0 rlang_0.4.6
Linux system:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux
Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.3.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.7.10 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_1.4.0 tidyr_1.1.3 tibble_3.1.2 ggplot2_3.3.4 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 cellranger_1.1.0 pillar_1.6.1 compiler_4.1.0 dbplyr_2.1.1 tools_4.1.0 digest_0.6.27 evaluate_0.14 jsonlite_1.7.2
[10] lifecycle_1.0.0 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.11 reprex_2.0.0 rstudioapi_0.13 DBI_1.1.1 cli_2.5.0 yaml_2.2.1
[19] haven_2.4.1 xfun_0.24 xml2_1.3.2 withr_2.4.2 httr_1.4.2 knitr_1.33 fs_1.5.0 generics_0.1.0 vctrs_0.3.8
[28] hms_1.1.0 grid_4.1.0 tidyselect_1.1.1 glue_1.4.2 R6_2.5.0 fansi_0.5.0 readxl_1.3.1 rmarkdown_2.9 farver_2.1.0
[37] modelr_0.1.8 magrittr_2.0.1 backports_1.2.1 scales_1.1.1 ellipsis_0.3.2 htmltools_0.5.1.1 rvest_1.0.0 assertthat_0.2.1 colorspace_2.0-1
[46] labeling_0.4.2 utf8_1.2.1 stringi_1.7.3 munsell_0.5.0 broom_0.7.7 crayon_1.4.1