[Python-Dev] datetime module enhancements (original) (raw)
Collin Winter collinw at gmail.com
Fri Mar 9 23:08:47 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, Steven Bethard <steven.bethard at gmail.com> wrote:
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.)
I can't say I'm well-versed in the intricacies of date/time issues, but what you say makes sense. This is exactly why I brought this patch up here : )
Thanks, Collin Winter
- Previous message: [Python-Dev] datetime module enhancements
- Next message: [Python-Dev] datetime module enhancements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]