comparing datetime with date
Alex Martelli
aleaxit at yahoo.com
Wed Sep 15 10:13:28 EDT 2004
Steve Holden <sholden at holdenweb.com> wrote:
> > Why should this be considered a bug? In my conception, a datetime.date
> > covers the whole range of times within the date, so that this equality
> > makes sense. It also allows for intuitive inequality comparisons
> > between datetime.datetime and datetime.date.
> >
> Well you do, of course, allow that this appeals to *your* intuition, but
> it seems much more reasonable to me to assume that a date, when compared
> to a datetime, should specify a single canonical time (such as midnight
> at the start of that date).
I have no opinion on the specific semantics so I prefer to look at the
logic of this... if we allow a date to compare equal to many different
datetimes, then we have a situation in which:
a == b
AND
a == c
BUT NOT
b == c
!!!
(just pick a as a date, b and c as two different datetimes within
it...).
This means == does not define an equivalence relationship, and THAT is
enough to send me into shivers and cold sweating. Either having a
comparison between date and datetime raise an exception, or consider a
date to be == to ONE specific datetime, will be OK from this POV. As
for which choice is better, if I was the one tasked to design this, I'd
go for "In the face of ambiguity, refuse the temptation to guess", and
raise an exception. But I don't feel particularly strongly about this.
Alex
More information about the Python-list
mailing list