[R] Daylight savings time and conversion to POSIXt (arghh!)
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Sat May 4 11:25:12 CEST 2002
Don MacQueen <macq at llnl.gov> writes:
> The third element is converted as if it were PDT, a 7 hour offset from
> GMT, when it is actually an 8 hour offset. This is not a problem. In
> fact, it is easy to handle both the first time and the last time
> correctly with
>
> > gcnv <- as.POSIXct(gdat,tz='GMT') + 28800
> > gcnv
> [1] "2002-04-07 01:30:00 PST" "2002-04-07 01:30:00 PST"
> [3] "2002-04-07 04:30:00 PDT"
>
> And verify that the first and last are two hours apart with:
> > diff(as.numeric(gcnv))
> [1] 0 7200
>
> But the middle one is still wrong. If they were correctly converted I
> would see 0 3600 7200.
>
> This suggests to me that as.POSIXct() isn't _fully_ honoring the tz argument.
Yes, there seems to be a bug there.
I get a slightly different effect though:
> as.POSIXct(gdat,tz='GMT')
[1] "2002-04-07 03:30:00 CEST" "2002-04-07 04:30:00 CEST"
[3] "2002-04-07 05:30:00 CEST"
> unclass(as.POSIXct(gdat,tz='GMT'))
[1] 1018143000 1018146600 1018150200
> Sys.putenv(TZ="US/Pacific")
> as.POSIXct(gdat,tz='GMT')
[1] "2002-04-06 17:30:00 PST" "2002-04-06 19:30:00 PST"
[3] "2002-04-06 19:30:00 PST"
> unclass(as.POSIXct(gdat,tz='GMT'))
[1] 1018143000 1018150200 1018150200
The workaround would be along the lines of
> {x<-Sys.getenv("TZ");Sys.putenv(TZ="GMT")
+ z<-as.POSIXct(gdat);Sys.putenv(TZ=x);z}+28800
[1] "2002-04-07 01:30:00 PST" "2002-04-07 03:30:00 PDT"
[3] "2002-04-07 04:30:00 PDT"
which is probably what as.POSIXlt should do internally too.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list