Pull requests

#1 Merged
Repository
Deleted repository
Branch
default (8b7e41a22ee5)
Repository
micktwomey/pyiso8601 pyiso8601
Branch
default

Make the inclusion of seconds optional in the date format.

Author
  1. Chris Down
Reviewers
Description

From the spec:

Complete date plus hours and minutes:

  • YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)

Parsing this example date currently results in a TypeError:

>>> iso8601.parse_date("1997-07-16T19:20+01:00")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/git/f1/f1scraper/f1scraper/venv2/lib/python2.7/site-packages/iso8601/iso8601.py", line 108, in parse_date
    int(groups["hour"]), int(groups["minute"]), int(groups["second"]),
TypeError: int() argument must be a string or a number, not 'NoneType'

This pull request allows such time structures:

>>> iso8601.parse_date("1997-07-16T19:20+01:00")
datetime.datetime(1997, 7, 16, 19, 20, tzinfo=<FixedOffset '+01:00'>)

A test is also included. Apologies for the random removal of whitespace that comes bundled, I can resubmit if this bothers you.

  • Learn about pull requests

Comments (4)

  1. Chris Down author

    Another way to do this would be to change the code when passing to datetime to become int(groups["second"] or 0), but I think that's a lot easier to miss in the huge blob of stuff being passed.

  2. Chris Down author

    I really need to be able to easily use this in development, and may be making additional patches soon, so I will be forced to fork if there's no response here soon.