[R] Problem with as.POSIXct on dates object

Denis Chabot chabotd at globetrotter.net
Mon Jul 20 11:16:35 CEST 2009


Hi,

if you look at my example in recent thread "Rép : [R] problem with  
as.POSIXct and daylight savings time", it appears that tz argument is  
used by as.POSIX.ct

Denis Chabot
Le 09-07-20 à 00:00, Remko Duursma a écrit :

>> as.POSIXct.dates does not make use of tz:
>
> Ok, but it is supposed to, right? Or maybe the documentation can be
> updated, because ?as.POSIXct does seem to imply the timezone is used
> (as it is for other methods of as.POSIXct).
>
> thanks,
> 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
>
>
>
> On Mon, Jul 20, 2009 at 1:41 PM, Gabor
> Grothendieck<ggrothendieck at gmail.com> wrote:
>> 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.
>>>
>>
>
> ______________________________________________
> 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