<div dir="ltr"><div class="gmail_extra"></div><br>On Thu, Sep 3, 2015 at 6:51 PM, Chris Barker <<a href="mailto:chris.barker@noaa.gov">chris.barker@noaa.gov</a>> wrote:<br>><br>> I know I only got it when someone explained the implementation:<br>><br>> "remove the tzinfo object, do the math, tack the tzinfo back on"<br>><br>> Simple elegant, and now I get it. And get why things go wonky with datetimes with two different tzinfo objects.<br>><br>> By the way, something like that should be in the docs.<br><br><br>Doc patches from good writers are always welcome, but in this case, I don't see what needs to be added to what the reference manual already says:<br><br>"""<br>Subtraction of a datetime from a datetime is defined only if both operands are naive, or if both are aware. If one is aware and the other is naive, TypeError is raised.<br><br>If both are naive, or both are aware and have the same tzinfo attribute, the tzinfo attributes are ignored, and the result is a timedelta object t such that datetime2 + t == datetime1. No time zone adjustments are done in this case.<br><br>If both are aware and have different tzinfo attributes, a-b acts as if a and b were first converted to naive UTC datetimes first. The result is (a.replace(tzinfo=None) - a.utcoffset()) -(b.replace(tzinfo=None) - b.utcoffset()) except that the implementation never overflows.<br>"""<br><br><a href="https://docs.python.org/3/library/datetime.html#datetime.datetime">https://docs.python.org/3/library/datetime.html#datetime.datetime</a><br><br>The only improvement that comes to mind is to make "Supported operations:" a linkable section.<br></div>