A better DateTime.rfc822() (Was: [Zope-Coders] Linux Test Results - Zope 2.6 branch - failures:1)

Lennart Regebro lennart@torped.se
Tue, 29 Oct 2002 11:34:12 +0100


How does this look to you guys? Should work, eh?

----

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


    def rfc822(self):
        """Return the date in RFC 822 format"""
        tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, 0.0))

        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)

----

The good thing is that it's now as far as I can see, completely independant
of what the local timezone is. I didn't find the _tzoffset method before,
because I was looking at the DateTime object, but it's not located there,
it's a module function, not a class method!

The test could then be like this:

        dt = DateTime('2002-05-02T08:00:00Z+00:00')
        self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0000')

        dt = DateTime('2002-05-02T08:00:00Z+02:00')
        self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0200')

        dt = DateTime('2002-05-02T08:00:00Z-02:00')
        self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 -0200')


This works on my computer, unless somebody screams, I'll check it in.