Skip to content

Commit

Permalink
Exchange.parse_date sanitized input
Browse files Browse the repository at this point in the history
  • Loading branch information
meold committed Jun 5, 2018
1 parent 253325b commit 01a9704
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions python/ccxt/base/exchange.py
Expand Up @@ -677,7 +677,6 @@ def iso8601(timestamp = None):
utc = datetime.datetime.utcfromtimestamp(int(round(timestamp / 1000)))
return utc.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-6] + "{:<03d}".format(int(timestamp) % 1000) + 'Z'
except (TypeError, OverflowError, OSError):
print('here')
return None

@staticmethod
Expand All @@ -696,13 +695,18 @@ def ymdhms(timestamp, infix=' '):
return utc_datetime.strftime('%Y-%m-%d' + infix + '%H:%M:%S')

@staticmethod
def parse_date(timestamp):
def parse_date(timestamp = None):
if timestamp is None:
return timestamp
if not isinstance(timestamp, str):
return None
if 'GMT' in timestamp:
string = ''.join([str(value) for value in parsedate(timestamp)[:6]]) + '.000Z'
dt = datetime.datetime.strptime(string, "%Y%m%d%H%M%S.%fZ")
return calendar.timegm(dt.utctimetuple()) * 1000
try:
string = ''.join([str(value) for value in parsedate(timestamp)[:6]]) + '.000Z'
dt = datetime.datetime.strptime(string, "%Y%m%d%H%M%S.%fZ")
return calendar.timegm(dt.utctimetuple()) * 1000
except (TypeError, OverflowError, OSError):
return None
else:
return Exchange.parse8601(timestamp)

Expand Down

0 comments on commit 01a9704

Please sign in to comment.