awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

write.xlsx() writes non-daylight savings POSIXct timestamps incorrectly #424

Open kwdoyle opened 6 years ago

kwdoyle commented 6 years ago

Expected Behavior

POSIXct timestamps not during daylight savings, such as '2011-02-04 11:01:37' and '2010-01-31 22:21:16', should write to an excel file as such when included with timestamps during daylight savings, such as '2010-03-16 03:01:23' and '2011-07-01 21:02:37'.

Actual Behavior

Timestamps not during daylight savings are written one hour ahead of the correct timestamp.

Screenshot

example

Steps to Reproduce the Problem

library(openxlsx)

test <- data.frame(ID = c(1,2,3,4,5),
                   DateTime = as.POSIXct(c('2010-03-16 03:01:23', '2011-02-04 11:01:37', '2011-07-01 21:02:37', 
                                           '2009-07-07 20:55:36', '2010-01-31 22:21:16'),
                                         format = '%Y-%m-%d %H:%M:%S',
                                         tz = "America/New_York"))

write.xlsx(test, "test.xlsx")

sessionInfo()

R version 3.5.1 (2018-07-02) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] openxlsx_4.1.0

loaded via a namespace (and not attached): [1] compiler_3.5.1 tools_3.5.1 yaml_2.2.0 Rcpp_0.12.18 zip_1.0.0