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

Devin Jeanpierre jeanpierreda at gmail.com
Wed May 9 20:27:20 CEST 2012


Egh, maybe I should elaborate.

On Wed, May 9, 2012 at 1:10 PM, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:
> Times are not a group -- there's no addition or multiplication
> operator among times. They only add against timedeltas, and timedeltas
> are the ones that need a 0 in order for that to work properly in some
> sense (since the result is a time).

In some system with addition, you generally want an "identity element"
(called 0), such that for every x, 0 + x = x.

+ is only defined with times for timedeltas, not with times and other
times. It doesn't make sense to add 3 'oclock to 5 'oclock. So if
we're talking about some 0 such that 0 + x = x, either 0 is the time
and x is the timedelta, or 0 is the timedelta and x is the time.

It doesn't make sense for the zero to be with the times, since the
result of addition with a timedelta shouldn't be a timedelta. There is
no time such that time + x = x for any timedelta x. This basically
means that there is _no time that makes sense as a "zero"_. At all.
You can pick some arbitrary one and call it zero, but it isn't zero in
an arithmetical sense.

On the other hand, there definitely is a zero timedelta: x +
timedelta(0) = x for every time x.

-- Devin



More information about the Python-ideas mailing list