Skip to content

Commit

Permalink
Do not change TZ env var in tests
Browse files Browse the repository at this point in the history
This caused the tests to fail in Prof Brian Ripley's M1 Mac setup, due
to timezone issues. Use a random timezone for the 'tzone' on the xts
object being plotted.
  • Loading branch information
joshuaulrich committed Nov 24, 2023
1 parent a917ff4 commit b6ddc04
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions inst/tinytest/test-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@ expect_equivalent(range(x), p$get_ylim(), info = info_msg)
get_xcoords_respects_object_tzone <-
function()
{
systz <- Sys.getenv("TZ")
on.exit(Sys.setenv(TZ = systz), add = TRUE)
# random timezone
tz <- sample(OlsonNames(), 1)
dttm <- seq(as.POSIXct("2023-01-01 01:23:45"), , 1, 5)
x <- xts(c(5, 1, 2, 4, 3), dttm, tzone = tz)

dates <- seq(as.Date("2023-01-01"), by = 1, length.out = 5)
x <- xts(c(5, 1, 2, 4, 3), order.by = dates)

Sys.setenv(TZ = "UTC")
print(p <- plot(x))
expect_identical("UTC", tzone(p$get_xcoords(x)),
info = "TZ = UTC")

Sys.setenv(TZ = "US/Central")
expect_identical("UTC", tzone(p$get_xcoords(x)),
info = "TZ = US/Central")
expect_identical(tz, tzone(p$get_xcoords(x)),
info = paste("TZ =", tz))
}
get_xcoords_respects_object_tzone()

0 comments on commit b6ddc04

Please sign in to comment.