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

Ethan Furman ethan at stoneleaf.us
Fri Mar 7 06:02:54 CET 2014


On 03/06/2014 08:13 AM, Alexander Belopolsky wrote:
>
> On Thu, Mar 6, 2014 at 8:21 AM, M.-A. Lemburg <mal at egenix.com <mailto:mal at egenix.com>> wrote:
>
>     > Are they all False? No, no they're not (unless your local timezone is UTC):
>     >
>     >>>> bool(utcmidnight)
>     > False
>     >>>> bool(naivemidnight)
>     > False
>     >>>> bool(localmidnight)
>     > True
>
>     Now this is a what I consider a valid argument for making a change.
>
>
> FWIW, I would be +0 for making a change so that t.tzinfo is not None
> implies bool(t.timetz()) is True.
>
> My intuition goes like this.  Given
>
>>>> from datetime import *
>>>> t1 = datetime(2014, 1, 1)
>>>> t2 = datetime(2014, 1, 1, 12)
>>>> t3 = datetime(2014, 1, 1, tzinfo=timezone.utc)
>
> Instance t1 has no time information, so t1.time() is false-y.

If datetime actually worked like that I would agree with you; but it doesn't -- it says you have the time of midnight on 
2014, 1, 1, not that you don't have a time at all.

--
~Ethan~


More information about the Python-ideas mailing list