Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wb_to_df] fix date1904 conversion #737

Merged
merged 1 commit into from
Aug 15, 2023
Merged

[wb_to_df] fix date1904 conversion #737

merged 1 commit into from
Aug 15, 2023

Conversation

JanMarvin
Copy link
Owner

⚠️ Previously wb_to_df() was not using date1904 detection, hence conversions via wb_to_df() were always assuming an origin of 1900-01-01 contrary to 1904-01-01. This file setting is somewhat exotic and we did provide tools to let the user detect the error, it is nevertheless a shameful mistake. Sorry.

DATE  <- as.Date("2015-02-07") + -10:10
POSIX <- as.POSIXct("2022-03-02 19:27:35") + -10:10
time <- data.frame(DATE, POSIX)

library(openxlsx2)
tmp <- temp_xlsx()
wb <- wb_workbook()
wb$workbook$workbookPr <- '<workbookPr date1904="true"/>'
wb$add_worksheet()$add_data(x = time)
wb$save(tmp)

wb_to_df(wb) %>% head()
#>         DATE               POSIX
#> 2 2015-01-28 2022-03-02 19:27:25
#> 3 2015-01-29 2022-03-02 19:27:26
#> 4 2015-01-30 2022-03-02 19:27:27
#> 5 2015-01-31 2022-03-02 19:27:28
#> 6 2015-02-01 2022-03-02 19:27:29
#> 7 2015-02-02 2022-03-02 19:27:30
wb_load(tmp)$to_df() %>% head()
#>         DATE               POSIX
#> 2 2015-01-28 2022-03-02 19:27:25
#> 3 2015-01-29 2022-03-02 19:27:26
#> 4 2015-01-30 2022-03-02 19:27:27
#> 5 2015-01-31 2022-03-02 19:27:28
#> 6 2015-02-01 2022-03-02 19:27:29
#> 7 2015-02-02 2022-03-02 19:27:30
wb_to_df(tmp) %>% head()
#>         DATE               POSIX
#> 2 2015-01-28 2022-03-02 19:27:25
#> 3 2015-01-29 2022-03-02 19:27:26
#> 4 2015-01-30 2022-03-02 19:27:27
#> 5 2015-01-31 2022-03-02 19:27:28
#> 6 2015-02-01 2022-03-02 19:27:29
#> 7 2015-02-02 2022-03-02 19:27:30

@JanMarvin JanMarvin added the bug 🐛 Something isn't working label Aug 15, 2023
@JanMarvin JanMarvin merged commit 4683e56 into main Aug 15, 2023
9 checks passed
@JanMarvin JanMarvin deleted the wb_1904 branch August 15, 2023 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant