[Zope-dev] DateTime.rfc822() bug?

Lennart Regebro lennart@torped.se
Tue, 15 Oct 2002 09:48:13 +0200


From: "Janko Hauser" <jh@comunit.de>
> Zope3 already uses the experimental datetime from Python2.3. From a
> quick look it seems to handle timezones. Perhaps you can look there for
> some ideas or use it instead.

It seems too risky to use experimental features from a version of python
that is ahead of the python version used by the rest of Zope 2.6.

I've solved it like this:

def _tzoffset2rfc822zone(seconds):
    return "%+03d%02d" % divmod( (-seconds/60), 60)


   def rfc822(self):
        """Return the date in RFC 822 format"""
        if self._tz == self._localzone0: #Use local standard time
            tzoffset = _tzoffset2rfc822zone(localzone)
        elif self._tz == self._localzone1: # Use local daylight saving time
            tzoffset = _tzoffset2rfc822zone(altzone)
        else:
            tzoffset = '-0000' # unknown time zone offset

        return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % (
            self._aday,self._day,self._amon,self._year,
            self._hour,self._minute,self._nearsec,tzoffset)

This will give you the correct timezone information in almost all cases.
Only when rfc822() is called on a DateTime which is in another timezone than
the server will '-0000' be used.

Best Regards

Lennart Regebro
Torped Strategi och Kommunikation AB