<br><br>On Wednesday, October 25, 2017, Chris Barker <<a href="mailto:chris.barker@noaa.gov">chris.barker@noaa.gov</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 25, 2017 at 4:22 PM, Alexander Belopolsky <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','alexander.belopolsky@gmail.com');" target="_blank">alexander.belopolsky@gmail.<wbr>com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>> times. The only difference is that instead of calling the type directly,<br>
> you call the appropriate classmethod.<br>
><br>
> What am I missing?<br>
<br>
</span>Nothing. The only annoyance is that the data processing code typically<br>
needs to know the type anyway, so the classmethod is one more variable<br>
to keep track of.</blockquote><div><br></div><div>I don't think anyone is arguing that is is hard to do either way, or that hard to use either way.</div><div><br></div><div>I think it comes down to a trade-off between:</div><div><br></div><div>Having an API for datetime that is like the datetime for number types:</div><div> </div><div><font face="monospace, monospace"> int(str(an_int)) == an_int</font></div><div><br></div><div> so:</div><div><br></div><div><font face="monospace, monospace"> datetime(str(a_datetime)) == a_datetime</font></div></div><div><br></div><div>Alexander strongly supports that.</div><div><br></div><div>Or an API that is perhaps more like the rest of the datetime api, which has a number of alternate constructors:</div><font face="monospace, monospace"><br> datetime.now()<br><br> datetime.fromordinal() <br><br> datetime.fromtimestamp()</font><br><br></div><div class="gmail_extra">And has:</div><div class="gmail_extra"><br><font face="monospace, monospace"> datetime.isoformat()</font><div><br></div><div>So a</div><div><font face="monospace, monospace"><br></font></div><div> <font face="monospace, monospace">datetime.fromisoformat()</font></div><div><br></div><div>would make a lot of sense.</div><div><br></div><div>I would note that the number types don't have all those alternate constructors Also, the number types mostly have a single parameter (except int has an optional base parameter). So I'm not sure the parallel is that strong.</div><div><br></div><div>Would it be horrible if we did both?</div><div><br></div><div>After all, right now, datetime has:</div><div><br></div><font face="monospace, monospace">In [16]: dt.isoformat()<br>Out[16]: '2017-10-25T16:30:48.744489'<br></font><br>and<font face="monospace, monospace"><br></font></div><div class="gmail_extra"><font face="monospace, monospace">In [18]: dt.__str__()<br>Out[18]: '2017-10-25 16:30:48.744489'<br></font><br></div><div class="gmail_extra">which do almost the same thing (I understand the "T" is option in iso 8601)</div><div class="gmail_extra"><br></div><div class="gmail_extra">However, maybe they are different when you add a time zone?</div><div class="gmail_extra"><br></div><div class="gmail_extra">ISO 8601 support offsets, but not time zones -- presumably the <font face="monospace, monospace">__str__</font> supports the full datetime tzinfo somehow. Which may be why<font face="monospace, monospace"> .isoformat()</font> exists.</div></div></blockquote><div><br></div><div>ISO8601 does support timezones.</div><div><a href="https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators">https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators</a><br></div><div><br></div><div>I might be wrong, but I think many of the third party libraries listed here default to either UTC or timezone-naieve timezones:</div><div><a href="https://github.com/vinta/awesome-python/blob/master/README.md#date-and-time">https://github.com/vinta/awesome-python/blob/master/README.md#date-and-time</a><br></div><div><br></div><div>Ctrl-F for 'tzinfo=' in the docs really doesn't explain how to just do it with my local time.</div><div><br></div><div>Here's an example with a *custom* GMT1 tzinfo subclass:</div><div><a href="https://docs.python.org/3/library/datetime.html#datetime.time.tzname">https://docs.python.org/3/library/datetime.html#datetime.time.tzname</a><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br></div><div class="gmail_extra">Though I don't think that means you couldn't have the __init__ parse proper ISO strings, in addition to the full datetime __str__ results.</div></div></blockquote><div><br></div><div>What would you call the str argument? Does it accept strptime args or only ISO8601? Would all of that string parsing logic be a performance regression from the current constructor? Does it accept None or empty string?</div><div><br></div><div>...</div><div><br></div><div>Deserializing dates from JSON (without #JSONLD and xsd:dateTime (ISO8601)) types is nasty, regardless (try/except, *custom* schema awareness). And pickle is dangerous.</div><div><br></div><div>AFAIU, we should not ever eval(repr(dt: datetime)).</div><div><br></div><div>...</div><div><br></div><div>Should the date time constructor support nanos= (just like time_ns())?</div><div><br></div><div>ENH: Add nanosecond support to the time and datetime constructors</div><div><br></div><div>...</div><div><br></div><div>The astropy Time class supports a string argument as the first parameter sometimes:</div><div><a href="http://docs.astropy.org/en/stable/time/#inferring-input-format">http://docs.astropy.org/en/stable/time/#inferring-input-format</a><br></div><div><br></div><div>Astropy does support a "year zero".</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
</div></div>
</blockquote>