[Python-Dev] Comparing date+time w/ just time

Jim Fulton jim at zope.com
Sat Oct 22 16:21:28 CEST 2005

skip at pobox.com wrote:
> With significant input from Fred I made some changes to xmlrpclib a couple
> months ago to better integrate datetime objects into xmlrpclib.  That raised
> some problems because I neglected to add support for comparing datetime
> objects with xmlrpclib.DateTime objects.  (The problem showed up in
> MoinMoin.)  I've been working on that recently (adding rich comparison
> methods to DateTime while retaining __cmp__ for backward compatibility), and
> have second thoughts about one of the original changes.
> I tried to support datetime, date and time objects.  My problems are with
> support for time objects.  Marshalling datetimes as xmlrpclib.DateTime
> objects is no problem (though you lose fractions of a second).  Marshalling
> dates is reasonable if you treat the time as 00:00:00. 

I don't think that is reasonable at all.  I would normally expect
a date to represent the whole day, not a particular, unspecified time.
Other people may have other expectations, but xmlrpclib should not
assume a particular interpretation.

 > I decided to marshal
> datetime.time objects by fixing the day portion of the xmlrpclib.DateTime
> object as today's date.  That's the suspect part.

Very very suspect. :)

> When I went back recently to add better comparison support, I decided to
> compare xmlrpclib.DateTime objects with time objects by simply comparing the
> HH:MM:SS part of the DateTime with the time object.  That's making me a bit
> queazy now.  datetime.time(hour=23) would compare equal to any DateTime with
> its time equal to 11PM.  Under the rule, "in the face of ambiguity, refuse
> the temptation to guess", I'm inclined to dump support for marshalling and
> comparison of time objects altogether.  Do others agree that was a bad idea?

I agree that it was a bad idea and that you should not try to marshal
time objects or compare time objects with DateTime objects.
Similarly, I strongly recommend that you also stop trying to marshal date
objects or compare date objects to DateTime objects.  After all,
if the datetime module doesn't allow compatison of date and datetime,
why should you try to compare date and DateTime?


Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org

More information about the Python-Dev mailing list