[Rd] Date time conversion bug (as.POSIXct)?

Dries Verheyen dries.verheyen at ees.kuleuven.be
Fri Jan 11 11:12:15 CET 2013


There is something wrong, I think, with the date-time conversion from a
numeric value if you use Central European Time (CET) as timezone.
Examples from R:

If I use the GMT time zone it is OK, I get the same time back from
as.POSIXct as I entered

> as.POSIXct(as.numeric(strptime("30/01/2012 13:00:00", format="%d/%m/%Y
> %H:%M:%S",tz="GMT")),origin="1970-01-01",tz="GMT")

[1] "2012-01-30 13:00:00 GMT"

If I go from CET to GMT there is also no problem:

>as.POSIXct(as.numeric(strptime("30/01/2012 13:00:00", format="%d/%m/%Y
%H:%M:%S",tz="CET")),origin="1970-01-01",tz="GMT")

[1] "2012-01-30 12:00:00 GMT"

In winter we are 1 hour ahead of Greenwich.

Also in summer it is OK (2 hours ahead of Greenwich):

>as.POSIXct(as.numeric(strptime("30/05/2012 13:00:00", format="%d/%m/%Y
%H:%M:%S",tz="CET")),origin="1970-01-01",tz="GMT")

[1] "2012-05-30 11:00:00 GMT"

The problem occurs when I use both the same time zone, if it is not GMT:

>as.POSIXct(as.numeric(strptime("30/01/2012 13:00:00", format="%d/%m/%Y
%H:%M:%S",tz="CET")),origin="1970-01-01",tz="CET")

[1] "2012-01-30 12:00:00 CET"

>as.POSIXct(as.numeric(strptime("30/05/2012 13:00:00", format="%d/%m/%Y
%H:%M:%S",tz="CET")),origin="1970-01-01",tz="CET")

[1] "2012-05-30 12:00:00 CEST"

> as.POSIXct(as.numeric(strptime("30/05/2012 13:00:00", format="%d/%m/%Y
> %H:%M:%S",tz="EST")),origin="1970-01-01",tz="EST")
[1] "2012-05-30 18:00:00 EST"

It looks like the function just puts the name of the time zone behind the
time calculated in GMT, and does not calculate the time in the asked time
zone.
Is it just how the function works? because for me it is a bit confusing like
that.



--
View this message in context: http://r.789695.n4.nabble.com/Date-time-conversion-bug-as-POSIXct-tp4655215.html
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list