[R-SIG-Finance] Help needed on Time Zone
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Feb 25 20:42:38 CET 2009
Hi Wang,
The current approach in xts has been to use GMT internally. This
really isn't ideal. The current code on R-forge has been changed to
simply let the system variable do the work.
The caveat is that if it is not set (via the shell or Sys.setenv(TZ=)
), then you can possibly encounter some odd things.
as.POSIXct and as.POSIXlt behave differently, sometimes ignoring the
TZ you have. A change (or 10) internal to xts has solved this issue
as well.
The current code is here: under /pkg
http://r-forge.r-project.org/scm/?group_id=118
The "R Packages" tab may not be updated yet. But the subversion code is.
For now you can do Sys.setenv(TZ="GMT") at the beginning of the
session and have everything default to GMT. This really isn't the
correct solution though.
I will be pushing the changes to CRAN soon.
Thanks,
Jeff
On Wed, Feb 25, 2009 at 1:32 PM, Yu, Wang <Wang.Yu at constellation.com> wrote:
> I am having problem with converting objects into xts objects and it looks to have something to do with time zone.
>
> It looks that it has something to do with my computer settings and I am wondering whether someone has seen this and solved it or the best practice is to just setting to "GMT"?
>
> Also, what is the default behavior if the Time Zone is unknown, defaulting to "GMT" already?
>
> Thanks, Wang
>
>
> Sys.getenv("TZ")
> TZ
> "est5edt"
>> Sys.timezone()
> [1] "EST"
>> z<- as.POSIXlt(Sys.time())
>> attributes(z)
> $names
> [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst"
>
> $class
> [1] "POSIXt" "POSIXlt"
>
> $tzone
> [1] "" "EST" "EDT"
>
> data(sample_matrix)
> sample.xts <- as.xts(sample_matrix, descr='my new xts object')
>
> Warning messages:
> 1: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), :
> unknown timezone '_st5edt'
> 2: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), :
> unknown timezone '_st5edt'
> 3: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), :
> unknown timezone '_st5edt'
> 4: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), :
> unknown timezone '_st5edt'
> 5: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), :
> unknown timezone '_st5edt'
>
> class(sample.xts)
> [1] "xts" "zoo"
>> str(sample.xts)
> An 'xts' object from 2007-01-02 to 2007-06-30 containing:
> Data: num [1:180, 1:4] 50 50.2 50.4 50.4 50.2 ...
> - attr(*, "dimnames")=List of 2
> ..$ : NULL
> ..$ : chr [1:4] "Open" "High" "Low" "Close"
> Indexed by objects of class: [POSIXt,POSIXct]
> Original class: 'matrix'
> xts Attributes:
> List of 1
> $ descr: chr "my new xts object"
>>>> This e-mail and any attachments are confidential, may contain legal,
> professional or other privileged information, and are intended solely for the
> addressee. If you are not the intended recipient, do not use the information
> in this e-mail in any way, delete this e-mail and notify the sender. CEG-IP2
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
--
Jeffrey Ryan
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
www.insightalgo.com
More information about the R-SIG-Finance
mailing list