datetime.time and midnight
Steve Holden
steve at holdenweb.com
Sun Feb 22 09:08:29 EST 2009
Ethan Furman wrote:
> Greetings, List!
>
> I was curious if anyone knew the rationale behind making midnight False?
>
> --> import datetime
> --> midnight = datetime.time(0,0,0)
> --> bool(midnight)
> False
>
> To my way of thinking, midnight does actually exist so it should be
> true. If datetime.time was measuring an *amount* of time, rather than a
> certain point during the day, then a time of 0:0:0 should certainly be
> False as it would mean no time had passed. However, since midnight does
> indeed exist (as many programmers have observed when deadlines approach
> ;) I would think it should be true.
One might ask the rationale behind treating a time as Boolean in the
first place. Let me guess: you are retrieving the times from a database,
and you are testing of the NULL value?
If that's the case, a simple "is not None" will overcome the objection.
Though I do agree it's a little weird for bool(midnight) to return
False. Probably worth a bug report. I imagine it's just returning the
bool of the underlying integer.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list