<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 23, 2015 at 12:22 PM, Lennart Regebro <span dir="ltr"><<a href="mailto:regebro@gmail.com" target="_blank">regebro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div id=":146" class="" style="overflow:hidden">It turns out it's very complex to solve this when internally storing<br>
the time as the local time. Basically you have to normalize the time<br>
(ie check if daylight savings have changed) when doing arithmetic, but<br>
normalize is doing arithmetic, and you get infinite recursion. </div></blockquote></div><br>This is not true.  Tim's analysis immortalized [1] at the end of the datetime.py file,</div><div class="gmail_extra">shows that UTC to local mapping can be unambiguously recovered from the</div><div class="gmail_extra">local to UTC rules using a simple finite algorithm.  Tim assumes [2] that standard (non-DST)</div><div class="gmail_extra">time offset is constant throughout the history, but this requirement can be relaxed to offset</div><div class="gmail_extra">changing no more than once in any 48 hour period (if you generously allow timezones</div><div class="gmail_extra">from -24 to 24 hours).</div><div class="gmail_extra"><br></div><div class="gmail_extra">Actually, it looks like I am repeating what I wrote back in April, so I'll stop with a</div><div class="gmail_extra">reference [3] to that post.</div><div class="gmail_extra"><br></div><div class="gmail_extra">[1]: <a href="https://hg.python.org/cpython/file/v3.5.0b1/Lib/datetime.py#l1935">https://hg.python.org/cpython/file/v3.5.0b1/Lib/datetime.py#l1935</a></div><div class="gmail_extra">[2]: <a href="https://hg.python.org/cpython/file/v3.5.0b1/Lib/datetime.py#l1948">https://hg.python.org/cpython/file/v3.5.0b1/Lib/datetime.py#l1948</a></div><div class="gmail_extra">[3]: <a href="https://mail.python.org/pipermail/python-dev/2015-April/139171.html">https://mail.python.org/pipermail/python-dev/2015-April/139171.html</a></div></div>