A better DateTime.rfc822() (Was: [Zope-Coders] Linux Test Results
- Zope 2.6 branch - failures:1)
Shane Hathaway
shane@zope.com
Tue, 29 Oct 2002 10:36:25 -0500
Lennart Regebro wrote:
> 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!
You'll want to use _tzoffset like this:
_tzoffset(self._tz, self._t)
That way, the actual zone offset can change over time, which follows the
complicated time zone conventions. If you have a moment, you could add
a docstring to the _tzoffset function, too.
Guido is writing a replacement datetime module for Zope 3 and Python
2.3. (And there was much rejoicing.)
Shane