[Zope3-checkins] CVS: Zope3/src/datetime - _datetime.py:1.4
Tim Peters
tim.one@comcast.net
Wed, 25 Dec 2002 23:50:17 -0500
Update of /cvs-repository/Zope3/src/datetime
In directory cvs.zope.org:/tmp/cvs-serv11249/src/datetime
Modified Files:
_datetime.py
Log Message:
timetz comparison, and datetimetz subtraction: reimplemented these to
work as documented. They weren't calling utcoffset() if both operands
had the same tzinfo object. That's fine if it so happens that the
shared tzinfo object returns a fixed offset (independent of operand),
but can give wrong results if that's not so, and the latter obtains in
a tzinfo subclass instance trying to model both standard and daylight
times.
This repairs some of the surprises in the sandbox US.py demo, but
not all of them. In a way, it makes one part even more surprising:
because addition of datetimetz and timedelta doesn't do anything with
tzinfo except attach it to the result, it's possible to add, e.g.,
one second to a datetimetz, and then see the result of that minus the
original datetimetz span an hour. This can happen at DST boundaries
(see US.py's doctest for concrete examples).
=== Zope3/src/datetime/_datetime.py 1.3 => 1.4 ===
--- Zope3/src/datetime/_datetime.py:1.3 Wed Dec 25 14:28:50 2002
+++ Zope3/src/datetime/_datetime.py Wed Dec 25 23:49:46 2002
@@ -1056,12 +1056,6 @@
type(other).__name__)
superself = super(timetz, self)
supercmp = superself.__cmp__
- mytz = self.__tzinfo
- ottz = None
- if isinstance(other, timetz):
- ottz = other.__tzinfo
- if mytz is ottz:
- return supercmp(other)
myoff = self._utcoffset()
otoff = other._utcoffset()
if myoff == otoff:
@@ -1672,12 +1666,10 @@
def __sub__(self, other):
supersub = super(datetimetz, self).__sub__
if not isinstance(other, datetime):
- return supersub(other) # XXX should set tzinfo on result
- mytz = self.__tzinfo
- ottz = None
- if isinstance(other, datetimetz):
- ottz = other.__tzinfo
- if mytz is ottz:
+ # This manages to attach self.tzinfo to the result via a
+ # devious route: self - timedelta is changed to
+ # self + (-timedelta) by datetime.__sub__, and the latter is
+ # handled by datetimetz.__add__.
return supersub(other)
myoff = self._utcoffset()
otoff = other._utcoffset()