[Python-ideas] strptime without second argument as an inverse to __str__

Andrew Barnert abarnert at yahoo.com
Thu Aug 7 16:52:03 CEST 2014


On Aug 7, 2014, at 5:35, Akira Li <4kir4.1i at gmail.com> wrote:

> Andrew Barnert
> <abarnert at yahoo.com.dmarc.invalid> writes:
> 
>> On Aug 5, 2014, at 14:46, Petr Viktorin
>> <encukou at gmail.com> wrote:
>>> When people say "iso" in the context of datestimes, they usually mean RFC 3339.
>> 
>> RFC 3339 is still more complicated than just reversing Python's str or
>> isoformat. IIRC (it's hard to check on my phone), it mandates that
>> parsers should accept 2-digit years (including 3-digit or
>> semicolon-and-two-digit years), lowercase T and Z, missing "-", and
>> other things that you shouldn't generate but some code might.
> 
> Please, don't spread misinformation.
> 
> Among the explicit rfc 3339 design goals are simplicity and human
> readability. 
> 
> Just read http://tools.ietf.org/html/rfc3339 (for an rfc it is
> relatively short and readable).

OK, I just read it. Among other things:

> NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this syntax may alternatively be lower case "t" or "z" respectively. This date/time format may be used in some environments or contexts that distinguish between the upper- and lower-case letters 'A'-'Z' and 'a'-'z' (e.g. XML). Specifications that use this format in such environments MAY further limit the date/time syntax so that the letters 'T' and 'Z' used in the date/time syntax must always be upper case. Applications that generate this format SHOULD use upper case letters. NOTE: ISO 8601 defines date and time separated by "T". Applications using this syntax may choose, for the sake of readability, to specify a full-date and full-time separated by (say) a space character. Klyne, et. al. Standards Track [Page 8]

(And there's also a whole section of interpreting "legacy"/"deprecated" 2-digit years and how you should handle them.)

So, is the RFC "spreading misinformation" about itself?

> The format is so simple that people just write adhoc parsers using
strptime() without installing any formal rfc3339 module (if it even
exists). 

Sure, and people also do that and call it an ISO parser. 

If it can't interoperable with everything compliant applications may generate (much less deprecated formats the standard doesn't allow you to generate but mandates how you parse and interpret), it's not accurate to call it an RFC 3339 parser (at least not in a general-purpose library).

As I said before, it's still certainly much easier to write an RFC 3339 parser than an ISO 8601 parser, but it's not as trivial as you're implying.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140807/bb1ddf82/attachment-0001.html>


More information about the Python-ideas mailing list