[R] time zones and the chron to POSIXct conversion
David Winsemius
dwinsemius at comcast.net
Sat Jun 16 06:26:25 CEST 2012
On Jun 15, 2012, at 11:18 PM, R. Michael Weylandt wrote:
> It does seem that as.POSIXct.date doesn't respect the tz= argument the
> generic suggests it would.
Why would a date function have a TZ? `as.Date` wouldn't.
> I'd think this is a bug that could be
> changed without breaking back-compatibility, but I don't have the
> power to make such things happen.
What bug?
Here is what ?chron says:
"If x is character then it will be converted using as.POSIXct (with
the format argument, if any, passed to as.POSIXct) and tz = "GMT" and
then converted to chron. "
So the call to `chron` below is using `as.POSIXct` first and then you
will be looking at differences in the printing conventions for POSIXct
and POSIXlt objects.
And then in the as.POSIX (lt and ct ) help pages we read:
"Character input is first converted to class "POSIXlt" by strptime:
numeric input is first converted to "POSIXct". :
> mode( chron('12/12/2000') )
[1] "numeric"
>
> R-Core ruling?
Er, not Core, just another useR.
>
> Michael
>
> On Fri, Jun 15, 2012 at 2:25 AM, Jannis <bt_jannis at yahoo.de> wrote:
>> Hey R folks,
>>
>>
>> i found some strange (to me) behaviour with chron to POSIXct
>> conversion. The
>> two lines of code result in two different results, on ewith the
>> correct time
>> zone, one without:
>>
>> library(chron)
>> as.POSIXct(chron('12/12/2000'), tz = 'UTC')
> format( as.POSIXct(chron('12/12/2000'), tz = 'UTC'), format="%Y-%m-
%d %H:%M %Z")
[1] "2000-12-11 19:00 EST"
>> as.POSIXlt(chron('12/12/2000'), tz = 'UTC')
> format( as.POSIXlt(chron('12/12/2000'), tz = 'UTC'), format="%Y-%m-
%d %H:%M %Z")
[1] "2000-12-12 00:00 UTC"
These both look correct to me. (Different output conventions.)
> as.POSIXct(chron('12/12/2000'), tz = 'UTC')
[1] "2000-12-11 19:00:00 EST"
> as.POSIXlt(chron('12/12/2000'), tz = 'UTC')
[1] "2000-12-12 UTC"
>>
>> Only the code below would give me a POSIXct object with the correct
>> time
>> zone:
>>
>> as.POSIXct(as.POSIXlt(chron('12/12/2000'), tz = 'UTC'))
I see the same output with that as I did with the second one:
> as.POSIXct(as.POSIXlt(chron('12/12/2000'), tz = 'UTC'))
[1] "2000-12-12 UTC"
If you want to force printing in a particular TZ then use format (or
strftime).
> format(as.POSIXct(chron('12/12/2000'), tz = 'UTC'), tz="GMT",
format="%Y-%m-%d %Z")
[1] "2000-12-12 GMT"
>>
>>
>> Is this a bug or desired behaviour?
Jannis; You have not demonstrated what output you saw, so this is
still a guessing game.
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list