xlsx icon indicating copy to clipboard operation
xlsx copied to clipboard

Issues when importing datetimes

Open ecorreig opened this issue 5 years ago • 2 comments

When parsing a simple xlsx file with european formatted datetimes I get that the function subtracts one second to all dates at 13 hours or at 1 hour. It only happens at these times, so I'm guessing it has to do with AM-PM to 24H conversion or something like that. The file would be something like:

time things
26/2/2019 9:00 a
26/2/2019 13:00 b
26/2/2016 21:00 c
27/2/2019 1:00 d

And the code is simply:

df <- read.xlsx("file.xlsx", sheetIndex = 1)

Thanks, Eudald

ecorreig avatar Jan 14 '20 12:01 ecorreig

Thanks for sharing this! I haven't had a chance to look at this, and it seems like the seconds / hours may be a different root cause, but any chance you have tried customizing the following? Our datetime formatting is defined by an option, and these are the defaults:

    options(xlsx.date.format = "m/d/yyyy")
    options(xlsx.datetime.format = "m/d/yyyy h:mm:ss")

Please note that we set these options universally on package load (which is wrong...), so you should set them after loading the xlsx package until we address this issue.

colearendt avatar Mar 22 '20 10:03 colearendt

Also, any chance you could use the reprex package to both write and read a sample xlsx in your example, perhaps also showing some of your locale settings / etc.? That would be helpful for our investigation!

https://www.jessemaegan.com/post/so-you-ve-been-asked-to-make-a-reprex/

colearendt avatar Mar 22 '20 10:03 colearendt