[Python-ideas] bool(datetime.time(0, 0))

Terry Reedy tjreedy at udel.edu
Mon May 7 19:27:01 CEST 2012


On 5/7/2012 12:33 PM, Antoine Pitrou wrote:
> On Mon, 7 May 2012 12:24:21 -0400
> Alexander Belopolsky
> <alexander.belopolsky at gmail.com>  wrote:
>> On Mon, May 7, 2012 at 12:06 PM, Antoine Pitrou<solipsis at pitrou.net>  wrote:
>>> Does midnight warrant any special shortcut for testing?
>>
>> I never needed it, but apparently it is common enough for users to
>> notice an complain.
>
> How so? Those users complain that midnight is false, not that they have
> trouble testing for midnight.
> That's the whole point really: they don't think about midnight as a
> special value, and they are surprised that it is.

It is only special in the representation because 24:00 == 00:00. I have 
the impression that European train timetables at least in decades past 
printed midnight arrival times as 24:00 instead of 00:00. I agree that 
that is an extremely thin reason for the current behavior. Someone 
printing timetables in that style should explicitly test arrivals for 
being midnight.

There have been cultures that started the day at dawn or noon, and in 
the US at least, we still restart half-days at both noon and midnight, 
so both would be special here.

Rather unusually, I disagree with Tim here: "It is odd, but really no 
odder than "zero values" of other types evaluating to false in Boolean 
contexts ;-)". Numerical 0 and empty collections are special and often 
need to be treated specially in a way that is untrue of midnight. I 
think treating it as special was a design mistake.

There have been discussions on python-list to the effect that if one 
wants to branch on something being None or not, one should be explicit 
-- 'is None' or 'is not None' -- to avoid accidentally picking up other 
null values.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list