Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dougedmunds opened this issue Jan 15, 2016 · 5 comments

Comments

@dougedmunds
Copy link

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

@e-mu-pi
Copy link

e-mu-pi commented Jan 15, 2016

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.

@dougedmunds dougedmunds changed the title IDateTime reports wrong date if time is greater than 11:59 (24 hr) IDateTime reports wrong date if time is greater than 15:59 (tz="America/Los_Angeles") Jan 15, 2016
@dougedmunds
Copy link
Author

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

@arunsrinivasan
Copy link
Member

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

@MichaelChirico
Copy link
Member

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

@MichaelChirico
Copy link
Member

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

arunsrinivasan added a commit that referenced this issue Jul 21, 2016
closes #1498; as.IDate doesn't lose timezone data given POSIXct input
@mattdowle mattdowle added this to the v1.10.6 milestone Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants