<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">>but is it that hard to parse arbitrary<br><blockquote type="cite"><blockquote type="cite"><span>ISO8601 strings in once you've gotten this far? It's a bit uglier than I'd</span><br></blockquote><blockquote type="cite"><span>like, but not THAT bad a spec.</span><br></blockquote><span></span><br><span>No, and in fact this PR is adapted from a *more general* ISO-8601 parser that I wrote (which is now merged into master on python-dateutil). In the CPython PR I deliberately limited it to be the inverse of `isoformat()` for two major reasons:</span><br><span></span><br><span>1. It allows us to get something out there that everyone can agree on - not only would we have to agree on whether to support arcane ISO8601 formats like YYYY-Www-D, </span></blockquote><div><br></div><div>I don’t know — would anyone complain about it supporting too arcane a format?</div><div><br></div><div>Also — “most ISO compliant “ date time strings would get us a long way.</div><br><blockquote type="cite"><span>but we also have to then discuss whether we want to be strict and disallow YYYYMM like ISO-8601 does, </span></blockquote><div><br></div><div>Well, I think disallowing something has little utility - we really don’t want this to be a validator.</div><div><br></div><blockquote type="cite"><span>do we want fractional minute support? What about different variations (we're already supporting replacing T with any character in `.isoformat()` and outputting time zones in the form hh:mm:ss, so what other non-compliant variations do we want to add..</span></blockquote><div><br></div><div>Wait — does datetime.isoformat() put out non-compliant strings?</div><div><br></div><div>Anyway, supporting all of what .isoformat() puts out, plus Most of iso8601 would be a great start.</div><br><blockquote type="cite"><span> - if it comes out of `isoformat()` it should be able to go back in througuh `fromisoformat()`.</span><br></blockquote><div><br></div><div>Yup.</div><div><br></div><div>But had anyone raised objections to it being more flexible?</div><br><blockquote type="cite"><span>2. It makes it *much* easier to understand what formats are supported. You can say, "This function is for reading in dates serialized with `.isoformat()`", you *immediately* know how to create compliant dates. </span></blockquote><div><br></div><div>We could still document that as the preferred form.</div><div><br></div><div>You’re writing the code, and I don’t have time to help, so by all means do what you think is best. </div><div><br></div><div>But if you’ve got code that’s more flexible, I can’t imagine anyone complaining about a more flexible parser.</div><div><br></div><div>Though I have a limited imagination about such things. </div><div><br></div><div>But I hope it will at least accept both with and without the T.</div><div><br></div><div>Thanks for working on this.</div><div><br></div><div>-Chris</div><div><br></div><blockquote type="cite"><span>On 12/07/2017 08:12 PM, Chris Barker wrote:</span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>Here is the PR I've submitted:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span><a href="https://github.com/python/cpython/pull/4699">https://github.com/python/cpython/pull/4699</a></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>The contract that I'm supporting (and, I think it can be argued, the only</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>reasonable contract in the intial implementation) is the following:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>    dtstr = dt.isoformat(*args, **kwargs)</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>    dt_rt = datetime.fromisoformat(dtstr)</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>    assert dt_rt == dt                    # The two points represent the</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>same absolute time</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>    assert dt_rt.replace(tzinfo=None) == dt.replace(tzinfo=None)   # And</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>the same wall time</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>that looks good.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br><blockquote type="cite"><span>I see this in the comments in the PR:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>"""</span><br></blockquote><blockquote type="cite"><span>This does not support parsing arbitrary ISO 8601 strings - it is only</span><br></blockquote><blockquote type="cite"><span>intended</span><br></blockquote><blockquote type="cite"><span>as the inverse operation of :meth:`datetime.isoformat`</span><br></blockquote><blockquote type="cite"><span>"""</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>what ISO8601 compatible features are not supported?</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>-CHB</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br></blockquote></body></html>