I have a vector of POSIXct objects:
> dates <- seq(as.POSIXct("2004-01-01", tz="EST"), as.POSIXct("2004-01-02", tz="EST"), as.difftime(6, units="hours"))
> dates
[1] "2004-01-01 00:00:00 EST" "2004-01-01 06:00:00 EST"
[3] "2004-01-01 12:00:00 EST" "2004-01-01 18:00:00 EST"
[5] "2004-01-02 00:00:00 EST"
I create an epoch
variable that defines a POSIXct object for the UNIX epoch:
> epoch <- strptime("1970-01-01 00:00:00", "%Y-%m-%d %H:%M:%S", tz="EST")
> class(epoch)
[1] "POSIXct" "POSIXt"
> epoch
[1] "1970-01-01 EST"
I then loop through the dates
vector and print out the value, offset from epoch
:
> for (d in dates) { print(as.POSIXct(d, origin=epoch, tz="EST")) }
[1] "2004-01-01 05:00:00 EST"
[1] "2004-01-01 11:00:00 EST"
[1] "2004-01-01 17:00:00 EST"
[1] "2004-01-01 23:00:00 EST"
[1] "2004-01-02 05:00:00 EST"
There seems to be a five-hour offset error between the values in dates
and the representation of those same values, relative to epoch
.
There is a +5 hr difference between EST and UTC, but I specified the EST time zone for epoch
with the tz
option. Printing out epoch
, there doesn't seem to be the time information, only the date.
Is there a bug with strptime
or as.POSIXct
, or am I calculating the offset or generating epoch
incorrectly?