mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
python3: support datetime produced by datetime.isoformat like '2015-01-17T00:15:29.515'
This commit is contained in:
parent
711d2c8cf4
commit
4198779b5b
@ -118,12 +118,13 @@ class ApiClient:
|
||||
for (key, val) in objDict.items()
|
||||
if key != 'swaggerTypes'}
|
||||
|
||||
def _iso8601Format(self, timesep, microsecond, zulu):
|
||||
def _iso8601Format(self, timesep, microsecond, offset, zulu):
|
||||
"""Format for parsing a datetime string with given properties.
|
||||
|
||||
Args:
|
||||
timesep -- string separating time from date ('T' or 't')
|
||||
microsecond -- microsecond portion of time ('.XXX')
|
||||
offset -- time offset (+/-XX:XX) or None
|
||||
zulu -- 'Z' or 'z' for UTC, or None for time offset (+/-XX:XX)
|
||||
|
||||
Returns:
|
||||
@ -132,19 +133,21 @@ class ApiClient:
|
||||
return '%Y-%m-%d{}%H:%M:%S{}{}'.format(
|
||||
timesep,
|
||||
'.%f' if microsecond else '',
|
||||
zulu or '%z')
|
||||
zulu or ('%z' if offset else ''))
|
||||
|
||||
# http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
_iso8601Regex = re.compile(
|
||||
r'^\d\d\d\d-\d\d-\d\d([Tt])\d\d:\d\d:\d\d(\.\d+)?(([Zz])|(\+|-)\d\d:?\d\d)$')
|
||||
r'^\d\d\d\d-\d\d-\d\d([Tt])\d\d:\d\d:\d\d(\.\d+)?(([Zz])|(\+|-)\d\d:?\d\d)?$')
|
||||
|
||||
def _parseDatetime(self, d):
|
||||
if d is None:
|
||||
return None
|
||||
m = ApiClient._iso8601Regex.match(d)
|
||||
if not m:
|
||||
raise Exception('datetime regex match failed "%s"' % d)
|
||||
timesep, microsecond, offset, zulu, plusminus = m.groups()
|
||||
format = self._iso8601Format(timesep, microsecond, zulu)
|
||||
if not zulu:
|
||||
format = self._iso8601Format(timesep, microsecond, offset, zulu)
|
||||
if offset and not zulu:
|
||||
d = d.rsplit(sep=plusminus, maxsplit=1)[0] + offset.replace(':', '')
|
||||
return datetime.datetime.strptime(d, format)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user