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

dougedmunds opened this issue Jan 15, 2016 · 5 comments


Copy link

@dougedmunds dougedmunds commented Jan 15, 2016

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:

Data in FiveMinute.csv file:
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:
csv1 = "FiveMinute.csv"
dt = fread(csv1)

as.POSIXct does not change the date

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

these calls produce incorrect output

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

Copy link

@e-mu-pi 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
Copy link

@dougedmunds dougedmunds commented Jan 15, 2016

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

Copy link

@arunsrinivasan arunsrinivasan commented Jul 21, 2016

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

Copy link

@MichaelChirico MichaelChirico commented Jul 21, 2016

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

Copy link

@MichaelChirico MichaelChirico commented Jul 21, 2016

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
None yet

No branches or pull requests

5 participants