rfc822 date header

Lars Wirzenius liw at iki.fi
Tue Apr 13 15:59:35 EDT 1999


jeffbauer at bigfoot.com:
> def strdate(self, timeval=None):
>     from time import gmtime, strftime, time
>     if timeval is None:
>         timeval = time()
>     return "Date: %s" % strftime('%a, %d %b %Y %H:%M:%S GMT',
> gmtime(timeval))

Here's what I wrote for Slime (thhe mailer I'm writing):

        def _date_header(self):
                """Return Date header reflecting current time."""
                # XXX this should probably communicate the local time zone
                # somehow
                t = time.gmtime(time.time())
                return "Date: %s, %02d %s %04d %02d:%02d:%02d GMT\n" % \
                        (rfc822._daynames[t[6]],
                         t[2],
                         rfc822._monthnames[t[1]],
                         t[0],
                         t[3],
                         t[4],
                         t[5])

Note that it isn't locale dependent.

(I apologize for the bad indentation of a whole tab, I haven't got around
to implementing proper indentation support in my editor.)




More information about the Python-list mailing list