[Python-ideas] Please reconsider the Boolean evaluation of midnight

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Mar 6 18:02:36 CET 2014


On Thu, Mar 6, 2014 at 11:50 AM, Tim Peters <tim.peters at gmail.com> wrote:

> Do you claim you still don't understand when bool(time) returns True
> and False?  Those are user docs.  I don't claim that reading them will
> make anyone feel good ;-), but I do believe the computation is
> described clearly enough to enable a reasonable user to predict the
> result in all cases.
>

I have to admit that before this discussion, I did not know about the
following
consequence of the documented behavior:

>>> from datetime import *
>>> t = datetime(2014, 1, 1, tzinfo=timezone.utc)
>>> tz1 = timezone(timedelta(hours=5))
>>> tz2 = timezone(timedelta(hours=-5))
>>> bool(t.timetz())
False
>>> bool(t.astimezone(tz1).timetz())
False
>>> bool(t.astimezone(tz2).timetz())
True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/78af5167/attachment.html>


More information about the Python-ideas mailing list