Issue 1673403: date-datetime comparison doesn't work (original) (raw)
Summary: bug #1028306 was not a bug, but the fix for it introduced one
Comparing a date to a datetime currently throws an exception. This makes no sense. In what way is:
datetime(2006, 1, 1, 0, 0, 0) < date(2007, 1, 1)
not a perfectly reasonable and well-defined comparison? Throwing an exception here violates the "Principle of Least Surprise" to a considerable degree.
Obviously some slight ambiguity arises if the date and the datetime differ only in the time part. There are two sensible responses in this situation that I can see:
Treat dates as if they have a time-part of midnight. This is my preferred solution, and it is already what the datetime module does, for example, when subtracting two dates.
Treat dates as if they refer to the entire day, i.e. if the date and datetime differ only in the time part then they are equal. This is consistent but becomes confusing in other situations such as when subtracting dates.