[ python-Bugs-1673403 ] date-datetime comparison doesn't work

SourceForge.net noreply at sourceforge.net
Thu Mar 8 22:09:53 CET 2007


Bugs item #1673403, was opened at 2007-03-04 06:51
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1673403&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jon Ribbens (jribbens)
>Assigned to: Tim Peters (tim_one)
Summary: date-datetime comparison doesn't work

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2007-03-08 16:09

Message:
Logged In: YES 
user_id=80475
Originator: NO

Tim, any thoughts?

----------------------------------------------------------------------

Comment By: Collin Winter (collinwinter)
Date: 2007-03-08 15:55

Message:
Logged In: YES 
user_id=1344176
Originator: NO

I think this warrants discussion on python-dev
(http://mail.python.org/mailman/listinfo/python-dev) as to which of the two
date interpretations to pick. Please post a description of the problem
there and ask for suggestions.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1673403&group_id=5470


More information about the Python-bugs-list mailing list