<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Sep 8, 2015 at 12:59 AM, Alexander Belopolsky <span dir="ltr"><<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@gmail.com</a>></span> 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"><span class=""><br><div class="gmail_quote">On Mon, Sep 7, 2015 at 9:57 PM, Alexander Belopolsky <span dir="ltr"><<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@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 dir="ltr">Solution 1: Make t1 > t0.<br><br>Solution 2: Leave t1 == t0, but make t1 != u1.</div></blockquote></div><br></span>Solution 3:  Leave t1 == t0, but make *both* t0 != u0 and t1 != u1 if t0.utcoffset() != t1.utcoffset().</div><div class="gmail_extra"><br></div><div class="gmail_extra">In other words,</div><div class="gmail_extra"><br></div><font face="monospace, monospace">def __eq__(self, other):<br>    n_self = self.replace(tzinfo=None)<br>    n_other = other.replace(tzinfo=None)<br>    if self.tzinfo is other.tzinfo:<br>        return n_self == n_other<br>    u_self = n_self - self.utcoffset()<br>    v_self = n_self - self.replace(fold=(1-self.fold)).utcoffset()<br>    u_other = n_other - other.utcoffset()<br>    v_other = n_other - other.replace(fold=(1-self.fold)).utcoffset()<br>    return u_self == u_other == v_self == v_other</font><div class="gmail_extra"><br></div><div class="gmail_extra">Before anyone complaints that this makes comparison 4x slower, I note that we can add obvious optimizations for the common tzinfo is datetime.timezone.utc and  isinstance(tzinfo, datetime.timezone) cases.  Users that truly want to compare aware datetime instances between two variable offset timezones, should realize that fold/gap detection in *both* r.h.s. and l.h.s. zones is part of the operation that they request.</div><div class="gmail_extra"><br></div><div class="gmail_extra">This solution has some nice properties compared to the solution 2: (1) it restores the transitivity - we no longer have u0 == t0 == t1 and t1 != u1; (2) it restores the symmetry between fold=0 and fold=1 while preserving a full backward compatibility.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I also think this solution makes an intuitive sense: since we cannot decide which of the two UTC times u0 and u1 should belong in the equivalency class of t0 == t1 - neither should.  "In the face of ambiguity" and all that.</div></div></blockquote><div><br></div><div>But it breaks compatibility: it breaks the rule that for fold=0 nothing changes.<br></div></div><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>