Skip to content

Errors when parsing some valid ISO8601 datetimes #82

@aaronzen

Description

@aaronzen

The iso8601 conversion fails currently on dates with hour or minute values of 0, if TZ data is present.

For example:

from pyswagger import utils
>>> utils.from_iso8601("2016-06-21T14:02:57Z")
datetime.datetime(2016, 6, 21, 14, 2, 57, tzinfo=<pyswagger.utils.FixedTZ object at 0x1070de910>)
>>> utils.from_iso8601("2016-06-21T00:02:57Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/pyswagger/utils.py", line 171, in from_iso8601
    raise ValueError('missing h:m when tzinfo is provided: [{0}]'.format(s))
ValueError: missing h:m when tzinfo is provided: [2016-06-21T00:02:57Z]

The issue is in 'pyswagger/utils.py', there is a boolean evaluation of hour/minute and since '0' is falsey the check fails. I believe the intention was to just test for None. The following change resolves the issue:

     if tz_s:
-        if not (hour and minute):
+        if hour == None or minute == None:
             raise ValueError('missing h:m when tzinfo is provided: [{0}]'.format(s))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions