[Zope3-checkins] CVS: Zope3/src/datetime - _datetime.py:1.6 doc.txt:1.4
Tim Peters
tim.one@comcast.net
Fri, 27 Dec 2002 16:34:52 -0500
Update of /cvs-repository/Zope3/src/datetime
In directory cvs.zope.org:/tmp/cvs-serv302/src/datetime
Modified Files:
_datetime.py doc.txt
Log Message:
datetimetz.astimezone(): don't call utcoffset() if the new timezone is
None; this sidesteps at least one "unbounded recursion surprise". Admit
to the None case in the docs.
=== Zope3/src/datetime/_datetime.py 1.5 => 1.6 ===
--- Zope3/src/datetime/_datetime.py:1.5 Thu Dec 26 19:15:49 2002
+++ Zope3/src/datetime/_datetime.py Fri Dec 27 16:34:51 2002
@@ -1614,14 +1614,16 @@
def astimezone(self, tz):
_check_tzinfo_arg(tz)
- offset = self.utcoffset()
- if offset is not None and tz is not None:
- newoffset = tz.utcoffset(self)
- if newoffset is not None:
- if not isinstance(newoffset, timedelta):
- newoffset = timedelta(minutes=newoffset)
- diff = offset - newoffset
- self -= diff # this can overflow; can't be helped
+ # Don't call utcoffset unless it's necessary.
+ if tz is not None:
+ offset = self.utcoffset()
+ if offset is not None:
+ newoffset = tz.utcoffset(self)
+ if newoffset is not None:
+ if not isinstance(newoffset, timedelta):
+ newoffset = timedelta(minutes=newoffset)
+ diff = offset - newoffset
+ self -= diff # this can overflow; can't be helped
return self.replace(tzinfo=tz)
def isoformat(self, sep='T'):
=== Zope3/src/datetime/doc.txt 1.3 => 1.4 ===
--- Zope3/src/datetime/doc.txt:1.3 Thu Dec 26 19:15:49 2002
+++ Zope3/src/datetime/doc.txt Fri Dec 27 16:34:51 2002
@@ -624,7 +624,7 @@
- astimezone(tz)
Return a datetimetz with the same date and time fields, and with
- tzinfo=tz. tz must be an instance of a tzinfo subclass.
+ tzinfo=tz. tz must be None or an instance of a tzinfo subclass.
- timetuple()
Return a 9-element tuple of the form returned by time.localtime().
@@ -1131,9 +1131,9 @@
tzinfo=None to remove a datetimetz's tzinfo member.
- astimezone(tz)
- Return a datetimetz with new tzinfo member. tz must be an instance
- of a tzinfo subclass. If self is naive, or if tz.utcoffset(self)
- returns None, self.astimezone(tz) is equivalent to
+ Return a datetimetz with new tzinfo member. tz must be None or an
+ instance of a tzinfo subclass. If tz is None, self is naive, or
+ tz.utcoffset(self) returns None, self.astimezone(tz) is equivalent to
self.replace(tzinfo=tz): a new timezone object is attached without
any conversion of date or time fields. If self is aware and
tz.utcoffset(self) does not return None, the date and time fields