Formatting RFC 822 date

Carey Evans careye at spamcop.net
Sun Apr 8 00:17:00 EDT 2001


Ben Hutchings <ben.hutchings at roundpoint.com> writes:

[...]

> The minute digits of the time offset weren't included just for fun;
> there really are zones that aren't offset by a whole number of hours.
> How about this instead:
> 
>     def zone822(dst):
>         offs = (0, time.timezone, time.altzone)[1 + dst]
>         return '%s%02d%02d' % ("+-"[offs >= 0],
>                                abs(offs) / 3600,
>                                (abs(offs) / 60) % 60)

Oops - I should have remembered that, especially since there's one of
those locations offshore from me here.

I also wonder now about the output when the dst flag is -1, since it's
not exactly clear when that will happen.  Maybe something like this
would be better:

    def zone822(dst):
        offs = (time.timezone, time.timezone, time.altzone)[1 + dst]
        return '%+.2d%.2d' % (offs / -3600, abs(offs / 60) % 60)

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	    "Quiet, you'll miss the humorous conclusion."



More information about the Python-list mailing list