[Zope-Checkins] CVS: Zope/lib/python/DateTime - DateTime.py:1.79.6.3

Lennart Regebro lennart@torped.se
Tue, 29 Oct 2002 13:13:12 -0500


Update of /cvs-repository/Zope/lib/python/DateTime
In directory cvs.zope.org:/tmp/cvs-serv4018/lib/python/DateTime

Modified Files:
      Tag: Zope-2_6-branch
	DateTime.py 
Log Message:
Remade rfc822() to utilize the _tzoffset method. Much cleaner and better code.
Remade the test code for rfc822() to provide more stable tests.

=== Zope/lib/python/DateTime/DateTime.py 1.79.6.2 => 1.79.6.3 ===
--- Zope/lib/python/DateTime/DateTime.py:1.79.6.2	Sat Oct 19 06:10:41 2002
+++ Zope/lib/python/DateTime/DateTime.py	Tue Oct 29 13:13:11 2002
@@ -362,6 +362,10 @@
     return int(yr),int(mo),int(dy)
 
 def _tzoffset(tz, t):
+    """Returns the offset in seconds to GMT from a specific timezone (tz) at 
+    a specific time (t).  NB! The _tzoffset result is the same same sign as 
+    the time zone, i.e. GMT+2 has a 7200 second offset. This is the opposite 
+    sign of time.timezone which (confusingly) is -7200 for GMT+2."""
     try:
         return DateTime._tzinfo[tz].info(t)[0]
     except:
@@ -400,7 +404,10 @@
     return rval
 
 def _tzoffset2rfc822zone(seconds):
-    return "%+03d%02d" % divmod( (-seconds/60), 60) 
+    """Takes an offset, such as from _tzoffset(), and returns an rfc822 
+       compliant zone specification. Please note that the result of 
+       _tzoffset() is the negative of what time.localzone and time.altzone is."""
+    return "%+03d%02d" % divmod( (seconds/60), 60) 
 
 
 class DateTime:
@@ -1437,12 +1444,7 @@
 
     def rfc822(self):
         """Return the date in RFC 822 format"""
-        if self._tz == self._localzone0: #Use local standard time
-            tzoffset = _tzoffset2rfc822zone(timezone)
-        elif self._tz == self._localzone1: # Use local daylight saving time
-            tzoffset = _tzoffset2rfc822zone(altzone)
-        else:
-            tzoffset = '-0000' # unknown time zone offset
+        tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, self._t))
             
         return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % (
             self._aday,self._day,self._amon,self._year,