Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Jul 23, 2015
1 parent b0d481a commit bea85e7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions connexion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ def produces_json(produces: list) -> bool:

def parse_datetime(s: str):
'''http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'''
if '.' in s:
time_secfrac = '.%f'
else:
# missing "time-secfrac" (milliseconds)
time_secfrac = ''
try:
# "Z" for UTC
if '.' in s:
datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%fZ')
else:
# missing "time-secfrac" (milliseconds)
datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')
datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S{}Z'.format(time_secfrac))
except:
# "+02:00" time zone offset
# remove the ":" first (%z expects "+0200")
x = s[:-3] + s[-2:]
if '.' in s:
datetime.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.%f%z')
else:
datetime.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S%z')
datetime.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S{}%z'.format(time_secfrac))

0 comments on commit bea85e7

Please sign in to comment.