[R] Daylight savings time and conversion to POSIXt (arghh!)

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sat May 4 11:48:46 CEST 2002


The issue is that you are supplying a time to strptime that does not exist
in the timezone your computer is running in.  I did not expect this to be
relevant, but it seems some OSes will adjust it (and Solaris and Linux
adjust it differently).

As Peter suggests, the workaround on Solaris (where TZ is always set) is
to set TZ to GMT.  But that's not what the code should do internally, as
on some systems it cannot be unset. I suspect I can work around this, with
one small problem (what should be isdst component be?).

I am getting a little fed up with working around undocumented `features'
of calendar-time support on various OSes!

On 4 May 2002, Peter Dalgaard BSA wrote:

> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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