[Python-ideas] Please reconsider the Boolean evaluation of midnight
Tim Peters
tim.peters at gmail.com
Thu Mar 6 02:53:02 CET 2014
[Bruce Leban]
> And the documentation is not exactly clear for understanding when a time
> object is falsey. In particular, the "converting it to minutes" part seems
> irrelevant
That's there because `utcoffset()` is defined to return minutes. A
rule is needed to specify how the naive time object and `utcoffset()`
interact to define the result.
> as a time of 1 microsecond from midnight is truthy and timedeltas
> are not numbers and are not in minutes
timedeltas have nothing to do with this. The docs could be expanded
to specify precisely how the naive time object is converted to
minutes, but I think that's so obvious it would just be tedious to do
so.
> Perhaps a reasonable improvement would be to change this to:
>
> a time object is considered to be true unless it represents exactly midnight
> local time, that is, it's false if subtracting the utcoffset() from the time
> produces an all-zero result (or it's all-zero to start with if the utcoffset
> is None).
You still need a rule to define _how_ "subtracting the utcoffset()
from the time" is intended to work, since arithmetic on naive time
objects is not defined. Add "convert it to minutes" ;-)
More information about the Python-ideas
mailing list