diff --git a/R/zzz.R b/R/zzz.R index a7b4c41d..b15e3326 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -5,22 +5,36 @@ ## it's in "/usr/share/zoneinfo" where CCTZ looks by default. On some systems ## (solaris, osx) it might be in a different location. So, help ourselves by ## setting the TZDIR env var, but only if it's not already set. - if (Sys.getenv("TZDIR") == "") { - ## adapted from OlsonNames function - tzdir <- - if (.Platform$OS.type == "windows") { - file.path(R.home("share"), "zoneinfo") - } else if (!file.exists("/usr/share/zoneinfo")) { - tzdirs <- c(file.path(R.home("share"), "zoneinfo"), - "/usr/share/lib/zoneinfo", "/usr/lib/zoneinfo", - "/usr/local/etc/zoneinfo", "/etc/zoneinfo", - "/usr/etc/zoneinfo") - tzdirs <- tzdirs[file.exists(tzdirs)] - if (length(tzdirs)) tzdirs[[1]] - else NULL - } - if (!is.null(tzdir)) { - Sys.setenv(TZDIR = tzdir) + + ## adapted from Syz.timezone and OlsonNames function + .find_tzdir <- function() { + if (.Platform$OS.type == "windows") + return(file.path(R.home("share"), "zoneinfo")) + tzdirs <- c("/usr/share/zoneinfo", + "/usr/share/lib/zoneinfo", + "/usr/lib/zoneinfo", + "/usr/local/etc/zoneinfo", + "/etc/zoneinfo", + "/usr/etc/zoneinfo", + "/usr/share/zoneinfo.default", + "/var/db/timezone/zoneinfo", + file.path(R.home("share"), "zoneinfo")) + tzdirs <- tzdirs[file.exists(tzdirs)] + if (length(tzdirs)) tzdirs[[1]] + else NULL + } + + tzdir <- Sys.getenv("TZDIR") + if (tzdir == "internal") { + Sys.setenv(TZDIR = file.path(R.home("share"), "zoneinfo")) + } else if (tzdir == "macOS") { + if (!is.null(dir <- .find_tzdir())) + Sys.setenv(TZDIR = dir) + } else if (tzdir == "") { + # not checking for /usr/share/zoneinfo which is the default in CCTZ + if (!file.exists("/usr/share/zoneinfo")) { + if (!is.null(dir <- .find_tzdir())) + Sys.setenv(TZDIR = dir) } }