Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ib_async/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ def formatIBDatetime(t: Union[dt.date, dt.datetime, str, None]) -> str:
return s


pythonTimeZonesByIb = {
"US/Central": "America/Chicago",
"US/Eastern": "America/New_York",
}


def parseIBDatetime(s: str) -> Union[dt.date, dt.datetime]:
"""Parse string in IB date or datetime format to datetime."""
if len(s) == 8:
Expand All @@ -589,6 +595,10 @@ def parseIBDatetime(s: str) -> Union[dt.date, dt.datetime]:
# 20221125 10:00:00 Europe/Amsterdam
s0, s1, s2 = s.split(" ", 2)
t = dt.datetime.strptime(s0 + s1, "%Y%m%d%H:%M:%S")
# Some zone names IB uses are unknown in python, map them
if s2 in pythonTimeZonesByIb:
s2 = pythonTimeZonesByIb[s2]

t = t.replace(tzinfo=ZoneInfo(s2))
else:
# YYYYmmdd HH:MM:SS
Expand Down