How is this not a bug?
as.POSIXct(as.Date("2013/01/01"))
Result:
[1] "2012-12-31 19:00:00 EST"
How is this not a bug?
as.POSIXct(as.Date("2013/01/01"))
Result:
[1] "2012-12-31 19:00:00 EST"
It calls the as.POSIXct.Date
method, which is
function (x, ...)
.POSIXct(unclass(x) * 86400)
Note that there is no possibility to pass a time zone to .POSIXct
although it has such a parameter:
function (xx, tz = NULL)
structure(xx, class = c("POSIXct", "POSIXt"), tzone = tz)
So this happens:
structure(unclass(as.Date("2013/01/01")) * 86400,
class = c("POSIXct", "POSIXt"), tzone = "EST")
#[1] "2012-12-31 19:00:00 EST"
Workaround if you want to convert Date
s:
structure(unclass(as.Date("2013/01/01")) * 86400,
class = c("POSIXct", "POSIXt"), tzone = "GMT")
#"2013-01-01 GMT"
Or modify as.POSIXct.Date
to
function (x, tz=NULL,...) .POSIXct(unclass(x) * 86400, tz = tz)