[New-bugs-announce] [issue15873] "datetime" cannot parse ISO 8601 dates and times
report at bugs.python.org
Thu Sep 6 23:08:50 CEST 2012
New submission from John Nagle:
The datetime module has support for output to a string of dates and times in ISO 8601 format ("2012-09-09T18:00:00-07:00"), with the object method "isoformat([sep])". But there's no support for parsing such strings. A string to datetime class method should be provided, one capable of parsing at least the RFC 3339 subset of ISO 8601.
The problem is parsing time zone information correctly.
The allowed formats for time zone are
empty - no TZ, date/time is "naive" in the datetime sense
Z - zero, or Zulu time, i.e. UTC.
[+-]nn.nn - offset from UTC
"strptime" does not understand timezone offsets. The "datetime" documentation suggests that the "z" format directive handles time zone info, but that's not actually implemented for input.
Pypi has four modules for parsing ISO 8601 dates. Each has least one major
problem in time zone handling:
Abandonware. Mishandles time zone when time zone is "Z" and
the default time zone is specified.
Always returns a "naive" datetime object, even if zone specified.
Fork of abandonware version above. Same bug.
Zope version. Imports the pytz module with the full Olsen time zone
database, but doesn't actually use that database.
Thus, nothing in Pypi provides a good alternative.
It would be appropriate to handle this in the datetime module. One small, correct, tested function would be better than the existing five bad alternatives.
components: Library (Lib)
title: "datetime" cannot parse ISO 8601 dates and times
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce