
On 3/12/07, Steven Bethard <steven.bethard@gmail.com> wrote:
[I'm not on this list, so please keep me in the CC if you reply]
On 3/11/07, Collin Winter <collinw@gmail.com> wrote:
On 3/9/07, Steven Bethard <steven.bethard@gmail.com> wrote on python-dev:
It's *not* okay to say that a date() is less than, greater than or equal to a datetime() if the year/month/day *does* match. The correct temporal relation is During, but Python doesn't have a During operator. During is not the same as less-than, greater-than or equal-to, so all of these should be False:: datetime.datetime(2006, 1, 1, 0, 0, 0) < datetime.date(2006, 1, 1) datetime.datetime(2006, 1, 1, 0, 0, 0) > datetime.date(2006, 1, 1) datetime.datetime(2006, 1, 1, 0, 0, 0) == datetime.date(2006, 1, 1) That is, the datetime() is not less than, greater than or equal to the corresponding date().
Some discussion of these kinds of issues is here: http://citeseer.ist.psu.edu/allen94actions.html The essence is that in order to properly compare intervals, you need the Meets, Overlaps, Starts, During and Finishes operators in addition to the Before (<) and Simulaneous (=) operators.
So, let's not conflate Before, After or Simultaneous with the other relations -- if it's not strictly Before (<), After (>) or Simultaneous (=), we can just say so by returning False.
It might be neat to add a __contains__ method to date() objects so that "datetime(2007, 1, 1, 0, 0, 0) in date(2007, 1, 1)" would be True. This would seem to fulfill the During operator.
That's a nice idea. With the simplest implementation, you could then guarantee that one of the following would always be true::
datetime < date datetime in date datetime > date
(That would actually conflate the Starts, Finishes and During relations in the __contains__ operator, but I think that's a perfectly reasonable interpretation, and I know it would be useful in my code at least.)
I'll work up a patch. Collin Winter