From 0933baee051e98271ff3e612a027c2367e417a35 Mon Sep 17 00:00:00 2001 From: shrektan Date: Thu, 27 Feb 2020 10:37:50 +0000 Subject: [PATCH 1/7] should set tz="UTC" explicitly in test 2137 otherwise it will fail if the locale timezone is not UTC --- inst/tests/tests.Rraw | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 7cc6819e8f..0be4075c42 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16821,10 +16821,10 @@ cols = c('x', 'y') test(2136, dt[, (cols) := lapply(.SD[get("x") == 1],function(x){x + 2L}), .SDcols = cols ,by = z], data.table(x = 1L + 2L, y = 2L + 2L, z = 3L)) # round, trunc should all be 'integer' and and have class 'ITime', #4207 -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))) +DT = data.table(hour31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:40", tz = "UTC"), by = "31 min", length.out = 9)), + hour30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "30 min", length.out = 9)), + minute31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "31 sec", length.out = 9)), + minute30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "30 sec", length.out = 9))) test(2137.01, TRUE, DT[, all(sapply(.SD, class) == "ITime")]) test(2137.02, TRUE, DT[, all(sapply(.SD, typeof) == "integer")]) test(2137.03, FALSE, DT[, all(round(hour30, "hours") == as.ITime(c("07:00", "08:00", "08:00", "09:00", "09:00", "10:00", "10:00", "11:00", "11:00")))]) From 78f629372e6b8a5f2aa736b33dfda15649282c75 Mon Sep 17 00:00:00 2001 From: shrektan Date: Fri, 28 Feb 2020 20:16:35 +0800 Subject: [PATCH 2/7] Revert "should set tz="UTC" explicitly in test 2137" This reverts commit 0933baee051e98271ff3e612a027c2367e417a35. --- inst/tests/tests.Rraw | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 0be4075c42..7cc6819e8f 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16821,10 +16821,10 @@ cols = c('x', 'y') test(2136, dt[, (cols) := lapply(.SD[get("x") == 1],function(x){x + 2L}), .SDcols = cols ,by = z], data.table(x = 1L + 2L, y = 2L + 2L, z = 3L)) # round, trunc should all be 'integer' and and have class 'ITime', #4207 -DT = data.table(hour31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:40", tz = "UTC"), by = "31 min", length.out = 9)), - hour30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "30 min", length.out = 9)), - minute31 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "31 sec", length.out = 9)), - minute30 = as.ITime(seq(as.POSIXct("2020-01-01 07:00:00", tz = "UTC"), by = "30 sec", length.out = 9))) +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))) test(2137.01, TRUE, DT[, all(sapply(.SD, class) == "ITime")]) test(2137.02, TRUE, DT[, all(sapply(.SD, typeof) == "integer")]) test(2137.03, FALSE, DT[, all(round(hour30, "hours") == as.ITime(c("07:00", "08:00", "08:00", "09:00", "09:00", "10:00", "10:00", "11:00", "11:00")))]) From 9ddf2a7f83bfcc82248e2558b4c4a39ecc60c081 Mon Sep 17 00:00:00 2001 From: shrektan Date: Fri, 28 Feb 2020 20:17:17 +0800 Subject: [PATCH 3/7] need to call `as.POSIXct()` with tz explicitly otherwise it will fail on macOS due to a possible bug of R's mac binary --- inst/tests/tests.Rraw | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 7cc6819e8f..83e1814f4d 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16558,6 +16558,8 @@ t0 = as.POSIXct('2019-10-01') test(2124.1, format(as.ITime(t0)), '00:00:00') test(2124.2, format(as.IDate(t0)), '2019-10-01') Sys.setenv(TZ=oldtz) +# This line is necessary due to a bug of R on macOS. Otherwise, `as.POSIXct()` will produce unexpected results. See https://github.com/Rdatatable/data.table/pull/4261#issuecomment-592484510 for details. +as.POSIXct("2020-01-01 07:00:40", tz = Sys.timezone()) # trunc.cols in print.data.table, #4074 old_width = options("width" = 40) From 0eba2f8170a68b00de2fd330b921af488277543f Mon Sep 17 00:00:00 2001 From: shrektan Date: Mon, 2 Mar 2020 00:40:36 +0800 Subject: [PATCH 4/7] Revert "need to call `as.POSIXct()` with tz explicitly otherwise it will fail on macOS due to a possible bug of R's mac binary" This reverts commit 9ddf2a7f83bfcc82248e2558b4c4a39ecc60c081. --- inst/tests/tests.Rraw | 2 -- 1 file changed, 2 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 83e1814f4d..7cc6819e8f 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16558,8 +16558,6 @@ t0 = as.POSIXct('2019-10-01') test(2124.1, format(as.ITime(t0)), '00:00:00') test(2124.2, format(as.IDate(t0)), '2019-10-01') Sys.setenv(TZ=oldtz) -# This line is necessary due to a bug of R on macOS. Otherwise, `as.POSIXct()` will produce unexpected results. See https://github.com/Rdatatable/data.table/pull/4261#issuecomment-592484510 for details. -as.POSIXct("2020-01-01 07:00:40", tz = Sys.timezone()) # trunc.cols in print.data.table, #4074 old_width = options("width" = 40) From 3841741d9ebad15294418b94751f9b0f5332c3fc Mon Sep 17 00:00:00 2001 From: shrektan Date: Mon, 2 Mar 2020 00:48:48 +0800 Subject: [PATCH 5/7] should call Sys.unsetenv() when we want to "unset" the env var unset and empty env var are different and it leads to unexpected results if env var "TZ" is set to "" on macOS --- inst/tests/tests.Rraw | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 7cc6819e8f..77c883c798 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16552,12 +16552,15 @@ dt = data.table(SomeNumberA=c(1,1,1),SomeNumberB=c(1,1,1)) test(2123, dt[, .(.N, TotalA=sum(SomeNumberA), TotalB=sum(SomeNumberB)), by=SomeNumberA], data.table(SomeNumberA=1, N=3L, TotalA=1, TotalB=3)) # 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) Sys.setenv(TZ='Asia/Jakarta') # UTC+7 t0 = as.POSIXct('2019-10-01') test(2124.1, format(as.ITime(t0)), '00:00:00') test(2124.2, format(as.IDate(t0)), '2019-10-01') -Sys.setenv(TZ=oldtz) +# empty env var is different from unset and it may need to unexpected +# results on macOS if env var TZ is set to empty +# see https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17724 +if (is.na(oldtz)) Sys.unsetenv('TZ') else Sys.setenv(TZ = oldtz) # trunc.cols in print.data.table, #4074 old_width = options("width" = 40) From 2a219d2bf67e8f8526aee019cdac93ed1655d37f Mon Sep 17 00:00:00 2001 From: Matt Dowle Date: Thu, 13 May 2021 17:43:37 -0600 Subject: [PATCH 6/7] revert whitespace --- inst/tests/tests.Rraw | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index e376f5d422..f87a2363d8 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16707,13 +16707,13 @@ dt = data.table(SomeNumberA=c(1,1,1),SomeNumberB=c(1,1,1)) test(2123, dt[, .(.N, TotalA=sum(SomeNumberA), TotalB=sum(SomeNumberB)), by=SomeNumberA], data.table(SomeNumberA=1, N=3L, TotalA=1, TotalB=3)) # system timezone is not usually UTC, so as.ITime.POSIXct shouldn't assume so, #4085 -oldtz = Sys.getenv('TZ', unset=NA) +oldtz=Sys.getenv('TZ', unset=NA) Sys.setenv(TZ='Asia/Jakarta') # UTC+7 t0 = as.POSIXct('2019-10-01') test(2124.1, format(as.ITime(t0)), '00:00:00') test(2124.2, format(as.IDate(t0)), '2019-10-01') if (is.na(oldtz)) Sys.unsetenv("TZ") else Sys.setenv(TZ=oldtz) -# careful to unset because TZ="" means UTC whereas unset TZ means local. #4261 needed this too. +# careful to unset because TZ="" means UTC whereas unset TZ means local # trunc.cols in print.data.table, #4074 old_width = options("width" = 40L) From dcfb0d61edc3ed1114aecaafc2e82a9712ba8ceb Mon Sep 17 00:00:00 2001 From: Matt Dowle Date: Thu, 13 May 2021 18:06:44 -0600 Subject: [PATCH 7/7] link comment to PRs --- inst/tests/tests.Rraw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index f87a2363d8..7959217d97 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16713,7 +16713,7 @@ t0 = as.POSIXct('2019-10-01') test(2124.1, format(as.ITime(t0)), '00:00:00') test(2124.2, format(as.IDate(t0)), '2019-10-01') if (is.na(oldtz)) Sys.unsetenv("TZ") else Sys.setenv(TZ=oldtz) -# careful to unset because TZ="" means UTC whereas unset TZ means local +# careful to unset because TZ="" means UTC whereas unset TZ means local, #4261 and #4464 # trunc.cols in print.data.table, #4074 old_width = options("width" = 40L)