Currently if x1 and x2 are POSIXct then c(x1, x2) will not have a
tzone attribute even if x1 or x2 or both do but it should.

This could be fixed with the following c.POSIXct:

c.POSIXct <- function (..., recursive = FALSE) {
        tzones <- lapply(list(...), attr, which = "tzone")
        lengths <- sapply(tzones, length)
        if (any(lengths > 1)) stop("tzone cannot have length greater than 1")
        which <- sapply(tzones, length) == 1
        tzone <- unique(unlist(tzones[which]))
        if (length(tzone) != 1) tzone <- NULL
structure(c(unlist(lapply(list(...), unclass))), class = c("POSIXt",
    "POSIXct"), tzone = tzone)
}

# test
x1 <- Sys.time()
x2 <- structure(x1, tzone = "UTC")
x3 <- structure(x1, tzone = "other")

# these all currently give NULL but with
# above give indicated value

attr(c(x1, x1), "tzone") # NULL
attr(c(x2, x2), "tzone") # "UTC"
attr(c(x1, x2), "tzone") # "UTC"
attr(c(x2, x1), "tzone") # "UTC"
attr(c(x1, x2, x3), "tzone") # NULL

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to