<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 5, 2014 at 11:24 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</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 style="overflow:hidden">There's also the argument from consistency: <span><span>midnight</span></span> is the zero point<br>



of the day, and zero is falsey. It would be surprising if something<br>
which is essentially zero became truthy.<br></div></blockquote></div><br><div>I don't think it's consistent now.</div><div><p style="text-align:justify;line-height:22.399999618530273px;font-family:'Lucida Grande',Arial,sans-serif">


In Boolean contexts ...<br></p><ul><li>a <a href="http://docs.python.org/3.4/library/datetime.html#datetime.timedelta" title="datetime.timedelta" style="color:rgb(48,48,111);text-decoration:none" target="_blank"><tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">timedelta</tt></a> object is considered to be true if and only if it isn’t equal to <tt style="background-color:rgb(236,240,243);padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">timedelta(0)</tt>.<br>


</li><li>all <a href="http://docs.python.org/3.4/library/datetime.html#datetime.date" title="datetime.date" style="color:rgb(48,48,111);text-decoration:none" target="_blank"><tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">date</tt></a> objects are considered to be true.<br>


</li><li>all <a href="http://docs.python.org/3.4/library/datetime.html#datetime.datetime" title="datetime.datetime" style="color:rgb(48,48,111);text-decoration:none" target="_blank"><tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">datetime</tt></a> objects are considered to be true.</li>


<li>a <a href="http://docs.python.org/3.4/library/datetime.html#datetime.time" title="datetime.time" style="color:rgb(48,48,111);text-decoration:none" target="_blank"><tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">time</tt></a> object is considered to be true if and only if, after converting it to minutes and subtracting <tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">utcoffset()</tt> (or <tt style="background-color:rgb(236,240,243);padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">0</tt> if that’s <tt style="background-color:rgb(236,240,243);padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">None</tt>), the result is non-zero.</li>


</ul><p></p></div>And the documentation is not exactly clear for understanding when a time object is falsey. In particular, the "converting it to minutes" part seems irrelevant as a time of 1 microsecond from midnight is truthy and timedeltas are not numbers and are not in minutes. Perhaps a reasonable improvement would be to change this to:</div>


<div class="gmail_extra"><ul><li>a <a href="http://docs.python.org/3.4/library/datetime.html#datetime.time" title="datetime.time" style="color:rgb(48,48,111);text-decoration:none" target="_blank"><tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">time</tt></a> object is considered to be true unless it represents exactly midnight local time, that is, it's false if subtracting the <tt style="background-color:transparent;padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">utcoffset()</tt> from the time produces an all-zero result (or it's all-zero to start with if the utcoffset is <tt style="background-color:rgb(236,240,243);padding:0px 1px;font-family:monospace,sans-serif;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">None</tt>).</li>


</ul></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><font face="arial, helvetica, sans-serif">--- Bruce<br></font><div><div><font face="arial, helvetica, sans-serif">Learn how hackers think: <a href="http://j.mp/gruyere-security" target="_blank">http://j.mp/gruyere-security</a></font></div>


</div><div><div style="font-family:arial;font-size:small"><a href="https://www.linkedin.com/in/bruceleban" style="color:rgb(17,85,204)" target="_blank">https://www.linkedin.com/in/bruceleban</a><br></div></div><div><br></div>


</div></div>
</div></div>