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:
iso8601 0.1.4
Abandonware. Mishandles time zone when time zone is "Z" and
the default time zone is specified.
iso8601.py 0.1dev
Always returns a "naive" datetime object, even if zone specified.
iso8601plus 0.1.6
Fork of abandonware version above. Same bug.
zc.iso8601 0.2.0
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)
messages: 169941
nosy: nagle
priority: normal
severity: normal
status: open
title: "datetime" cannot parse ISO 8601 dates and times
type: enhancement
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15873>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com