need to call as.POSIXct() with tz after "TZ" ENV VAR gets changed#4261
need to call as.POSIXct() with tz after "TZ" ENV VAR gets changed#4261
Conversation
otherwise it will fail if the locale timezone is not UTC
Codecov Report
@@ Coverage Diff @@
## master #4261 +/- ##
=======================================
Coverage 99.46% 99.46%
=======================================
Files 75 75
Lines 14712 14712
=======================================
Hits 14634 14634
Misses 78 78 Continue to review full report at Codecov.
|
|
@jangorecki can we add Maybe also something |
|
@MichaelChirico windows builds runs on https://gitlab.com/Rdatatable/data.table/-/jobs/443985937/artifacts/file/bus/test-rel-win/data.table.Rcheck/tests_x64/main.Rout |
|
@jangorecki I see, good to know. Is that a property of the docker image? I don't see anything in In any case, it appears we missed this issue anyway -- would it make sense to add a different TZ & locale to one of the other builds? @shrektan what's your |
Sys.timezone()error relatedCode that below comment useslibrary(data.table)
DT = data.table(hour31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:40"), by = "31 min", length.out = 9)),
hour30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00"), by = "30 min", length.out = 9)),
minute31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00"), by = "31 sec", length.out = 9)),
minute30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00"), by = "30 sec", length.out = 9)))
DTAn interesting observation is:Before I run After What's more interesting is:If I add a Again, I checked both |
|
@MichaelChirico no, windows builds runs not in a docker but using ssh executor on windows OS directly. |
|
OK I just find out the root causes: data.table/inst/tests/tests.Rraw Lines 16554 to 16560 in b1b1832 I'm not sure it's a bug of R or not but we just need to call In addition, it may happen on Mac Only because I can't reproduce it on Windows and since the CI works fine, I doubt it happens on Linux - but I would happy if somebody can help me to verify this. # system timezone is not usually UTC, so as.ITime.POSIXct shouldn't assume so, #4085
as.POSIXct("2020-01-01 07:00:40")
#> [1] "2020-01-01 07:00:40 CST"
oldtz=Sys.getenv('TZ')
Sys.setenv(TZ='Asia/Jakarta') # UTC+7
as.POSIXct("2020-01-01 07:00:40")
#> [1] "2020-01-01 07:00:40 WIB"
Sys.setenv(TZ=oldtz)
####### this is unexpected ##########
as.POSIXct("2020-01-01 07:00:40")
#> [1] "2020-01-01 15:00:40 CST"
####### after call as.POSIXct() with tz explicitly ###########
as.POSIXct("2020-01-01 07:00:40", tz = Sys.timezone())
#> [1] "2020-01-01 07:00:40 CST"
####### it falls back to normal ###########
as.POSIXct("2020-01-01 07:00:40")
#> [1] "2020-01-01 07:00:40 CST"Created on 2020-02-28 by the reprex package (v0.3.0) sessioninfo |
This reverts commit 0933bae.
… on macOS due to a possible bug of R's mac binary
28dea3a to
9ddf2a7
Compare
|
on On my Mac I see: |
…ill fail on macOS due to a possible bug of R's mac binary" This reverts commit 9ddf2a7.
unset and empty env var are different and it leads to unexpected results if env var "TZ" is set to "" on macOS
|
|
||
| # system timezone is not usually UTC, so as.ITime.POSIXct shouldn't assume so, #4085 | ||
| oldtz=Sys.getenv('TZ') | ||
| oldtz = Sys.getenv('TZ', unset = NA) |

Otherwise, it will fail on macOS. See #4261 (comment) for the details.
Update: I've reported this on https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17724
Update: As Luke Tierney points out (in the above URL), unset the env var by calling
Sys.setenv(TZ="")is wrong. The correct way is to callSys.unsetenv("TZ").