Skip to content

Commit

Permalink
parse_datetime function added
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling committed Sep 24, 2017
1 parent ec28625 commit fd7c84f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions betfairlightweight/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ class FileNotFoundError(OSError):
numeric_types = (int, float)
integer_types = (int,)

# will attempt to use c libraries if installed

try:
import ujson as json
except ImportError:
import json

try: # todo
try:
import ciso8601
parse_datetime = ciso8601.parse_datetime_unaware

def parse_datetime(datetime_string):
return ciso8601.parse_datetime_unaware(datetime_string)
except ImportError:
parse_datetime = datetime.datetime.strptime(None, "%Y-%m-%dT%H:%M:%S.%fZ")
def parse_datetime(datetime_string):
return datetime.datetime.strptime(datetime_string, "%Y-%m-%dT%H:%M:%S.%fZ")
4 changes: 2 additions & 2 deletions betfairlightweight/resources/baseresource.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
import ciso8601

from ..compat import (
basestring,
integer_types,
json,
parse_datetime,
)


Expand All @@ -29,7 +29,7 @@ def strip_datetime(value):
"""
if isinstance(value, basestring):
try:
return ciso8601.parse_datetime_unaware(value)
return parse_datetime(value)
except ValueError:
return
elif isinstance(value, integer_types):
Expand Down

0 comments on commit fd7c84f

Please sign in to comment.