[Zope3-checkins] CVS: Zope3/src/datetime - _datetime.py:1.9 doc.txt:1.6

Tim Peters tim.one@comcast.net
Tue, 31 Dec 2002 10:57:42 -0500


Update of /cvs-repository/Zope3/src/datetime
In directory cvs.zope.org:/tmp/cvs-serv16623/src/datetime

Modified Files:
	_datetime.py doc.txt 
Log Message:
Inlined a timezone conversion routine that turned out to be called only
once.  Updated the docs.  The hoped-for treatment of DST endcases
remains unclear.


=== Zope3/src/datetime/_datetime.py 1.8 => 1.9 ===
--- Zope3/src/datetime/_datetime.py:1.8	Tue Dec 31 01:06:55 2002
+++ Zope3/src/datetime/_datetime.py	Tue Dec 31 10:57:42 2002
@@ -1617,31 +1617,6 @@
         raise ValueError("astimezone():  tz.utcoffset() gave "
                          "inconsistent results; cannot convert")
 
-    def _finish_astimezone(self, other, otoff):
-        # If this is the first hour of DST, it may be a local time that
-        # doesn't make sense on the local clock, in which case the naive
-        # hour before it (in standard time) is equivalent and does make
-        # sense on the local clock.  So force that.
-        alt = other - _HOUR
-        altoff = alt.utcoffset()
-        if altoff is None:
-            self._inconsistent_utcoffset_error()
-        # Are alt and other really the same time?  alt == other iff
-        # alt - altoff == other - otoff, iff
-        # (other - _HOUR) - altoff = other - otoff, iff
-        # otoff - altoff == _HOUR
-        diff = otoff - altoff
-        if diff == _HOUR:
-            return alt      # use the local time that makes sense
-
-        # There's still a problem with the unspellable (in local time)
-        # hour after DST ends.
-        if self == other:
-            return other
-        # Else there's no way to spell self in zone other.tz.
-        raise ValueError("astimezone():  the source datetimetz can't be "
-                         "expressed in the target timezone's local time")
-
     def astimezone(self, tz):
         _check_tzinfo_arg(tz)
         # This is somewhat convoluted because we can only call
@@ -1678,7 +1653,31 @@
             otoff = other.utcoffset()
             if otoff is None:
                 self._inconsistent_utcoffset_error()
-        return self._finish_astimezone(other, otoff)
+
+        # If this is the first hour of DST, it may be a local time that
+        # doesn't make sense on the local clock, in which case the naive
+        # hour before it (in standard time) is equivalent and does make
+        # sense on the local clock.  So force that.
+        alt = other - _HOUR
+        altoff = alt.utcoffset()
+        if altoff is None:
+            self._inconsistent_utcoffset_error()
+        # Are alt and other really the same time?  alt == other iff
+        # alt - altoff == other - otoff, iff
+        # (other - _HOUR) - altoff = other - otoff, iff
+        # otoff - altoff == _HOUR
+        diff = otoff - altoff
+        if diff == _HOUR:
+            return alt      # use the local time that makes sense
+
+        # There's still a problem with the unspellable (in local time)
+        # hour after DST ends.
+        if self == other:
+            return other
+        # Else there's no way to spell self in zone other.tz.
+        raise ValueError("astimezone():  the source datetimetz can't be "
+                         "expressed in the target timezone's local time")
+
 
     def isoformat(self, sep='T'):
         s = super(datetimetz, self).isoformat(sep)


=== Zope3/src/datetime/doc.txt 1.5 => 1.6 ===
--- Zope3/src/datetime/doc.txt:1.5	Mon Dec 30 14:45:53 2002
+++ Zope3/src/datetime/doc.txt	Tue Dec 31 10:57:42 2002
@@ -2,8 +2,6 @@
 =========
 - The Python implementation is missing docstrings in many places.
 
-- LaTeXize the docs.
-
 
 CLOSED
 ======
@@ -833,9 +831,6 @@
 unless user code calls tzinfo methods directly.  The intent is that the
 tzinfo methods interpret dt as being in local time, and not need to worry
 about objects in other timezones.
-XXX That isn't always true yet:  datetimetz.astimezone(tz) can pass
-XXX a datetimetz with a "foreign" tzinfo to a self.tzinfo method.  This
-XXX needs to be repaired.
 
 Example tzinfo classes:
 
@@ -1160,11 +1155,11 @@
     any conversion of date or time fields.  If self is aware and
     tz.utcoffset(self) does not return None, the date and time fields
     are adjusted so that the result is local time in timezone tz,
-    representing the same UTC time as self.  self.astimezone(tz) is then
-    equivalent to
-        (self - (self.utcoffset() - tz.utcoffset(self)).replace(tzinfo=tz)
-    where the result of tz.uctcoffset(self) is coerced to a timedelta if
-    needed.
+    representing the same UTC time as self.
+    XXX The treatment of endcases remains unclear:  for DST-aware
+    XXX classes, one hour per year has two spellings in local time, and
+    XXX another hour has no spelling in local time.
+    
 
   - timetuple()
     Like datetime.timetuple(), but sets the tm_isdst flag according to