Author nagle
Recipients Alexander.Belopolsky, Arfrever, belopolsky, nagle, r.david.murray
Date 2012-09-07.01:51:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346982682.26.0.456476239617.issue15873@psf.upfronthosting.co.za>
In-reply-to
Content
Re: "%z format is supported".

That's platform-specific; the actual parsing is delegated to the C library.  It's not in Python 2.7 / Win32:

  ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S%z'

It really shouldn't be platform-specific; the underlying platform is irrelevant to this task.  That's more of a documentation error; the features not common to all supported Python platforms should not be mentioned in the documentation.  

Re: "I would very much like such promiscuous parser to be implemented in datetime.__new__. "

For string input, it's probably better to do this conversion in a specific class-level function.  Full ISO 8601 dates/times generally come from computer-generated data via a file or API.  If invalid text shows up, it should be detected as an error, not be heuristically interpreted as a date.  There's already "fromtimestamp" and "fromordinal", 
and "isoformat" as an instance method, so "fromisoformat" seems reasonable.

I'd also suggest providing a standard subclass of tzinfo in datetime for fixed offsets.  That's needed to express the time zone information in an ISO 8601 date. The new "fromisoformat" would convert an ISO 8601 date/time would be convertible to a time-zone "aware" datetime object.  If converted back to an ISO 8601 string with .isoformat(), the round trip should preserve the original data, including time zone offset.

(Several more implementations of this conversion have turned up.  In addition to the four already mentioned, there was one in xml.util, and one in feedparser. There are probably more yet to be found.)
History
Date User Action Args
2012-09-07 01:51:24naglesetrecipients: + nagle, belopolsky, Arfrever, r.david.murray, Alexander.Belopolsky
2012-09-07 01:51:22naglesetmessageid: <1346982682.26.0.456476239617.issue15873@psf.upfronthosting.co.za>
2012-09-07 01:51:20naglelinkissue15873 messages
2012-09-07 01:51:02naglecreate