[R] Problem with as.POSIXct on dates object

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jul 20 05:41:36 CEST 2009


as.POSIXct.dates does not make use of tz:

> as.POSIXct.dates
function (x, ...)
{
    if (inherits(x, "dates")) {
        z <- attr(x, "origin")
        x <- as.numeric(x) * 86400
        if (length(z) == 3L && is.numeric(z))
            x <- x + as.numeric(ISOdate(z[3L], z[1L], z[2L],
                0))
        return(structure(x, class = c("POSIXt", "POSIXct")))
    }
    else stop(gettextf("'%s' is not a \"dates\" object",
deparse(substitute(x))))
}
<environment: namespace:base>


On Sun, Jul 19, 2009 at 11:30 PM, Remko Duursma<remkoduursma at gmail.com> wrote:
> Dear R-helpers,
>
>
> I have a problem converting an object made with the 'chron' function
> to a POSIXct object:
>
> # Make date based on DOY
> dat <- chron(dates=232, origin.=c(month=1, day=1, year=2008))
>
> dat
> #[1] 08/20/08
>
> # Converting to POSIXct uses current timezone (Sydney):
> as.POSIXct(dat)
> #[1] "2008-08-20 10:00:00 EST"
>
> # Setting GMT timezone has no effect?
> as.POSIXct(dat, tz="GMT")
> #[1] "2008-08-20 10:00:00 EST"
>
> # But to POSIXlt works fine:
> as.POSIXlt(dat, tz="GMT")
> #[1] "2008-08-20 GMT"
>
> Is this behavior expected? If so, can you explain why?
>
> thanks for your help,
> Remko
>
>
>
> -------------------------------------------------
> Remko Duursma
> Post-Doctoral Fellow
>
> Centre for Plants and the Environment
> University of Western Sydney
> Hawkesbury Campus
> Richmond NSW 2753
>
> Dept of Biological Science
> Macquarie University
> North Ryde NSW 2109
> Australia
>
> Mobile: +61 (0)422 096908
>
> ______________________________________________
> 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