[Python-Dev] datetime module enhancements (original) (raw)
Steven Bethard steven.bethard at gmail.com
Fri Mar 9 23:03:02 CET 2007
- Previous message: [Python-Dev] datetime module enhancements
- Next message: [Python-Dev] datetime module enhancements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3/9/07, Collin Winter <collinw at gmail.com> wrote:
One solution that just occurred to me -- and that skirts the issue of choosing an interpretation -- is that, when comparing date and datetime objects, the datetime's .date() method is called and the result of that call is compared to the original date. That is,
datetimeobj < dateobj is implicitly equivalent to datetimeobj.date() < dateobj
Using the .date() is fine when the year/month/day doesn't match. So the following are fine:: datetime.datetime(2005, 1, 1, 0, 0, 0) < datetime.date(2006, 1, 1) datetime.datetime(2007, 1, 1, 0, 0, 0) > datetime.date(2006, 1, 1) 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.
(I believe these semantics would be just fine for both of the examples offered so far, but let me know if you think that's not true.)
STeVe
I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
- Previous message: [Python-Dev] datetime module enhancements
- Next message: [Python-Dev] datetime module enhancements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]