[New-bugs-announce] [issue15873] "datetime" cannot parse ISO 8601 dates and times

John Nagle 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:

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 <report at bugs.python.org>
<http://bugs.python.org/issue15873>
_______________________________________


More information about the New-bugs-announce mailing list