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

Tim Peters tim.peters at gmail.com
Thu Mar 6 18:29:37 CET 2014


[Tim Peters]
>> For example, modular arithmetic on time
>> objects was a possibility.  In that case, time(0, 0, 0) would become
>> "a zero value"

[Greg Ewing <greg.ewing at canterbury.ac.nz>]
> That only follows if you interpret "modular arithmetic on
> time objects" as meaning that you can directly add one time
> object to another.

Of course.

> But that would be confusing times with timedeltas. The concept of
> a zero *timedelta* makes sense, but not a "zero time".

The only difference between time and timedelta is in implementation
details.  In effect, time values are (or _can_ be viewed as) a subset
of timedelta values, restricted to non-negative durations strictly
less than 24 hours.  From that point of view, it's obvious how to do
modular (mod 24 hours) arithmetic on time values.  And some people
said they wanted that.

It wasn't obviously useful enough to implement at first, but neither
did we want to preclude it in the future.  I don't personally want it.


>> People can say that "midnight" isn't a compelling "sentinel value",
>> and I agree about the "compelling" part, but in all implementation
>> respects it does _act_ as "a sentinel value".

> If someone is using midnight to represent an unspecified
> time, I'd say they have a bug. An appointment scheduled at
> midnight is not the same as an appointment that's not
> scheduled at all.

Again obviously so.  In much the same way, there's nothing forbidden
about -1 as an integer, but it's ubiquitously used as an error return
in CPython's implementation.  That doesn't mean CPython is buggy, it
implies that CPython has other ways to distinguish whether a -1 return
does or does not mean "error!".  For example, in some applications
(not all), "exactly midnight"  simply can't happen as a legitimate
starting or ending time.


More information about the Python-ideas mailing list