
Change the time zone of a sub-daily zoo object
change_tz.RdChanges the time zone used by the time index of a sub-daily zoo object
whose index inherits from POSIXct or POSIXlt.
Arguments
- x
zooobject with a sub-dailyPOSIXctorPOSIXlttime index.- new.tz
character. Time zone to assign to the output time index.
- old.tz
character or
NULL. Time zone currently used by the time index. WhenNULL, it is inferred fromattr(time(x), "tzone"). When provided, it must match the detected time zone when the time index already has one.- ...
further arguments passed to or from other methods.
Details
Both old.tz and new.tz are checked against
OlsonNames.
change_tz() preserves the represented instants and changes their time
zone for display and downstream calendar grouping. For example, midnight UTC is
shown as the previous evening in "America/Santiago" when the applicable
UTC offset is negative. It does not reinterpret clock labels in a new time zone.
The values and dimensions of x are preserved; only the time index is
changed.
Author
Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
Examples
dates <- seq(as.POSIXct("2001-01-01 00:00:00", tz="UTC"),
by="hour", length.out=3)
x <- zoo(1:3, dates)
y <- change_tz(x, new.tz="America/Santiago")
time(y)
#> [1] "2000-12-31 21:00:00 -03" "2000-12-31 22:00:00 -03"
#> [3] "2000-12-31 23:00:00 -03"
## The represented instants and the observed values are preserved.
identical(as.numeric(time(x)), as.numeric(time(y)))
#> [1] TRUE
identical(coredata(x), coredata(y))
#> [1] TRUE