datetime.time and midnight

Ethan Furman ethan at stoneleaf.us
Sun Feb 22 16:20:59 EST 2009


Tim Rowe wrote:
> 2009/2/22 Mark Dickinson <dickinsm at gmail.com>:
>   
>> On Feb 21, 10:44 pm, Ethan Furman <et... at stoneleaf.us> wrote:
>>
>>     
>>> --> midnight = datetime.time(0,0,0)
>>> --> bool(midnight)
>>> False
>>>       
>> I'd call this a bug.
>>     
>
> No more so than zero being false. Zero exists too (check my bank
> balance). Once you've accepted non-Boolean types having Boolean
> values, the logic of what value they have is always going to be a bit
> hairy. If you're unsure of the logic, just test against a value or a
> range. After all, what value do you *expect* a time of day to have
> when interpreted as a Boolean? If you don't have an expectation, why
> are you interpreting it as a Boolean?
>
>   
As Steve Holden correctly guessed, my use case is with databases (more 
accurately, with dBase and VFP dbf files).  As I was creating a dbf 
date/datetime/time wrapper for the existing datetime data types I 
noticed that it is *not* possible to have a false date, nor a false 
date/time, so I was surprised with the false time.

So partly because of dates and datetimes, partly because objects are 
true unless special effort is made to have them be false, and partly 
because midnight is in fact a time of day, and not a lack of a time of 
day, I do indeed expect it to be True.
--
~Ethan~



More information about the Python-list mailing list