View | Details | Raw Unified | Return to bug 17186
Collapse All | Expand All

(-)src/library/base/R/datetime.R (-1 / +18 lines)
Lines 25-31 Link Here
25
    if(!location || nzchar(tz)) return(Sys.getenv("TZ", unset = NA_character_))
25
    if(!location || nzchar(tz)) return(Sys.getenv("TZ", unset = NA_character_))
26
    lt <- normalizePath("/etc/localtime") # Linux, macOS, ...
26
    lt <- normalizePath("/etc/localtime") # Linux, macOS, ...
27
    if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)
27
    if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)
28
    else NA_character_
28
    else if (lt == "/etc/localtime" &&
29
             file.exists("/etc/timezone") &&
30
             dir.exists("/usr/share/zoneinfo")) { # Debian etc.
31
        info <- file.info(normalizePath("/etc/timezone"), extra_cols = FALSE)
32
        if (!info$isdir && info$size <= 200L) {
33
            tz2 <- tryCatch(readBin("/etc/timezone", "raw", 200L),
34
                            error = function(e) raw(0L))
35
            if (length(tz2) > 0L &&
36
                all(tz2 %in% as.raw(c(9:10, 13L, 32:126)))) {
37
                tz2 <- gsub("^[[:space:]]+|[[:space:]]+$", "", rawToChar(tz2))
38
                tzpath <- file.path("/usr/share/zoneinfo", tz2)
39
                if (file.exists(tzpath) && !dir.exists(tzpath) &&
40
                    identical(file.size(normalizePath(tzpath)),
41
                              file.size(lt))) tz2
42
                else NA_character_
43
            } else NA_character_
44
        } else NA_character_
45
    } else NA_character_
29
}
46
}
30
47
31
as.POSIXlt <- function(x, tz = "", ...) UseMethod("as.POSIXlt")
48
as.POSIXlt <- function(x, tz = "", ...) UseMethod("as.POSIXlt")

Return to bug 17186