Learn R Programming

xts (version 0.13.1)

tzone: Get or Replace the Timezone of an xts Object's Index

Description

Generic functions to get or replace the timezone of an xts object's index.

Usage

tzone(x, ...)
tzone(x) <- value

# S3 method for xts tzone(x, ...) # S3 method for xts tzone(x) <- value

##### The functions below are DEPRECATED ##### indexTZ(x, ...) indexTZ(x) <- value

Value

A one element named vector containing the timezone of the object's index.

Arguments

x

an xts object

value

a valid timezone value (see OlsonNames())

...

arguments passed to other methods

Author

Jeffrey A. Ryan

Details

Internally, an xts object's index is a numeric value corresponding to seconds since the epoch in the UTC timezone. When an xts object is created, all time index values are converted internally to POSIXct (which is also in seconds since the UNIX epoch), using the underlying OS conventions and the TZ environment variable. The xts() function manages timezone information as transparently as possible.

The tzone<- function does not change the internal index values (i.e. the index will remain the same time in the UTC timezone).

See Also

POSIXt index has more information on the xts index, tformat describes how the index values are formatted when printed, and tclass provides details how xts handles the class of the index.

Examples

Run this code
# Date indexes always have a "UTC" timezone
x <- xts(1, Sys.Date())
tzone(x)
str(x)
print(x)

# The default 'tzone' is blank -- your machine's local timezone,
# determined by the 'TZ' environment variable.
x <- xts(1, Sys.time())
tzone(x)
str(x)

# now set 'tzone' to different values
tzone(x) <- "UTC"
str(x)

tzone(x) <- "America/Chicago"
str(x)

y <- timeBasedSeq('2010-01-01/2010-01-03 12:00/H')
y <- xts(seq_along(y), y, tzone = "America/New_York")

# Changing the tzone does not change the internal index values, but it
# does change how the index is printed!
head(y)
head(.index(y))
tzone(y) <- "Europe/London"
head(y)          # the index prints with hours, but
head(.index(y))  # the internal index is not changed!

Run the code above in your browser using DataLab