[R] problem with as.POSIXct and daylight savings time

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jul 19 19:06:36 CEST 2009


as.chron.POSIXt has an offset= argument and it may be
a vector:

> args(chron:::as.chron.POSIXt)
function (x, offset = 0, tz = "GMT", ...)

On Sun, Jul 19, 2009 at 9:10 AM, Denis Chabot<chabotd at globetrotter.net> wrote:
> [was "  [R] end of daylight saving time"]
>
> Hi,
>
> I got no reply with the previous subject line, probably a bad choice
> of subject on my part, so here it is again.
>
> I read from the help on DateTimeClasses and various posts on this list
> that, quite logically, one needs to specify if DST is active or not
> when time is between 1 and 2 AM on the first Sunday in November (for
> North America in recent years).
>
> This I can do for on date at a time:
>
> a <- as.POSIXct("2008-11-02 01:30:00", tz="EST5EDT")  # to get
> automatic use of DST
> b <- as.POSIXct("2008-11-02 01:30:00", tz="EST")  # to tell T this is
> the second occurrence of 1:30 that day, in ST
> difftime(b,a)
>
> Time difference of 1 hours
>
> But why can't I do the following, which appears to be a typical R way
> of doing things, to handle several date-times at once?
>
> c <- rep("2008-11-02 01:30:00", 2)
> tzone = c("EST5EDT", "EST")
>
> as.POSIXct(c, tz=tzone)
> Erreur dans strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
>  valeur 'tz' incorrecte
>
> ???
>
> Thanks,
>
> Denis Chabot
>
> sessionInfo()
> R version 2.9.1 Patched (2009-07-09 r48929)
> x86_64-apple-darwin9.7.0
>
> locale:
> fr_CA.UTF-8/fr_CA.UTF-8/C/C/fr_CA.UTF-8/fr_CA.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] tools_2.9.1
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list