[Python-checkins] python/nondist/sandbox/datetime US.py,1.10,1.11 datetime.py,1.127,1.128 doc.txt,1.73,1.74

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Fri, 27 Dec 2002 13:31:43 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv11381

Modified Files:
	US.py datetime.py doc.txt 
Log Message:
datetimetz.astimezone():  If the new timezone is None, don't bother
calling self.utcoffset().  This sidesteps at least one "unbounded
recursion surprise".  Fixed the astimezone() docs to admit to the
None case.


Index: US.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/US.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** US.py	27 Dec 2002 20:37:00 -0000	1.10
--- US.py	27 Dec 2002 21:31:40 -0000	1.11
***************
*** 98,107 ****
  
          # Can't compare naive to aware objects, so strip the timezone from
!         # dt first.  Caution:  dt.astimezone(None) instead can lead to
!         # unbounded recursion, because astimezone() has to call utcoffset()
!         # to determine whether it returns None, and utcoffset() ends up
!         # calling this (dst()) method again.
!         dt = dt.replace(tzinfo=None)
!         if start <= dt < end:
              return self.dstoff
          else:
--- 98,103 ----
  
          # Can't compare naive to aware objects, so strip the timezone from
!         # dt first.
!         if start <= dt.astimezone(None) < end:
              return self.dstoff
          else:

Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.127
retrieving revision 1.128
diff -C2 -d -r1.127 -r1.128
*** datetime.py	27 Dec 2002 00:13:55 -0000	1.127
--- datetime.py	27 Dec 2002 21:31:40 -0000	1.128
***************
*** 1615,1626 ****
      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
          return self.replace(tzinfo=tz)
  
--- 1615,1628 ----
      def astimezone(self, tz):
          _check_tzinfo_arg(tz)
!         # 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)
  

Index: doc.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/doc.txt,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -d -r1.73 -r1.74
*** doc.txt	27 Dec 2002 00:13:55 -0000	1.73
--- doc.txt	27 Dec 2002 21:31:40 -0000	1.74
***************
*** 625,629 ****
    - 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.
  
    - timetuple()
--- 625,629 ----
    - astimezone(tz)
      Return a datetimetz with the same date and time fields, and with
!     tzinfo=tz.  tz must be None or an instance of a tzinfo subclass.
  
    - timetuple()
***************
*** 1132,1138 ****
  
    - 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
      self.replace(tzinfo=tz):  a new timezone object is attached without
      any conversion of date or time fields.  If self is aware and
--- 1132,1138 ----
  
    - astimezone(tz)
!     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