Data.table: IDateTime reports wrong date if time is greater than 15:59 (tz="America/Los_Angeles")

Created on 15 Jan 2016  ·  5Comments  ·  Source: Rdatatable/data.table

IDateTime() generates wrong date if the time portion is greater than 15:59 (tz="America/Los_Angeles")
The conversion of all records that have the time at / after 15:59 of my time zone.

Details of problem at:
http://stackoverflow.com/questions/34786887/why-does-idatetime-convert-to-the-wrong-date

Data in FiveMinute.csv file:
Time,High,Low,Open,Close,Vol
2016/01/13 11:00,4.8100,4.7875,4.8050,4.7900,543
2016/01/13 11:05,4.7950,4.7825,4.7900,4.7925,781
2016/01/13 11:10,4.7925,4.7750,4.7925,4.7775,2787
2016/01/13 11:15,4.7850,4.7775,4.7800,4.7800,659
2016/01/13 17:00,4.7800,4.7700,4.7800,4.7700,371
2016/01/13 17:05,4.7750,4.7700,4.7700,4.7700,158
2016/01/13 17:10,4.7675,4.7550,4.7675,4.7550,288

R script:
library(data.table)
csv1 = "FiveMinute.csv"
dt = fread(csv1)
dput(dt)

as.POSIXct does not change the date

as.POSIXct(dt$Time)
as.POSIXct(dt$Time, "%Y/%m/%d %H:%M", tz="")

these calls produce incorrect output

IDateTime(as.POSIXct(dt$Time))
IDateTime(as.POSIXct(dt$Time, tz=""))
IDateTime(as.POSIXct(dt$Time, tz="America/Los_Angeles"))
IDateTime(as.POSIXct(dt$Time, "%Y/%m/%d %H:%M", tz=""))
IDateTime(as.POSIXct(dt$Time, "%Y/%m/%d %H:%M", tz="America/Los_Angeles"))
dput(IDateTime(as.POSIXct(dt$Time, "%Y/%m/%d %H:%M", tz="America/Los_Angeles")))
dput(IDateTime(as.POSIXct(dt[,Time], "%Y/%m/%d %H:%M", tz="America/Los_Angeles")))

System: Win10x64 R 3.2.2 data.table 1.9.6

bug idatitime

All 5 comments

The second post on issue #977 gives a specialization of as.IDate.POSIXct that I use. It will use the time zone specified by the POSIXct. It will also do conversion if you pass in a tz argument, but note that currently IDateTime does not pass along extra arguments to as.IDate. In practice, I also redefine IDateTime to pass along the ... arguments to as.IDate and as.ITime.

It's not clear to me what the standards and goals are around IDateTime, so I have not tried to make a PR for this, but I think it will address your issue.

Thank you, e-mu-pi. You have identified the cause of the problem with IDateTime that I am experiencing.

@MichaelChirico do you think you could take a look at this? (since you've fixed some issues / made improvements with IDate / ITime..)

@arunsrinivasan sure, i'll put it on my task list.

Original post a bit unclear.

Minimal example:

as.POSIXct("2016/01/13 17:00", tz = "America/Los_Angeles")
# [1] "2016-01-13 17:00:00 PST"
IDateTime(as.POSIXct("2016/01/13 17:00", tz = "America/Los_Angeles"))
#         idate    itime
# 1: 2016-01-14 17:00:00
Was this page helpful?
0 / 5 - 0 ratings