strftime: %Z, timezone, and all that 
Author Message
 strftime: %Z, timezone, and all that

i tried adding a date header to an email as per the python docs, like so:

def _dateStamp():
    """Stamp an rfc-8222 compilant date for the header."""

    return strftime("%a, %d %b %Y %H:%M:%S %Z", localtime())

this is what it looks like in the (outgoing) email file:

    Date: Tue, 26 Jun 2001 23:40:46 Eastern Daylight Time

and when i use smtplib to deliver da mail, the (received) date gets mangled
like so:

    Date: Tue, 26 Jun 2001 23:40:46 +0000 (Eastern)

seems like %Z in strftime should either return a +0500 or an EDT, no?
the Python doc says this:

"""
Here is an example, a format for dates compatible with that specified in the
RFC 822 Internet email standard. 6.1

Quote:
>>> from time import *
>>> strftime("%a, %d %b %Y %H:%M:%S %Z", localtime())

'Sat, 27 Jan 2001 05:15:05 EST'
"""

les schaffer



Sun, 14 Dec 2003 12:04:10 GMT  
 strftime: %Z, timezone, and all that

Quote:

> i tried adding a date header to an email as per the python docs, like so:
...
>     return strftime("%a, %d %b %Y %H:%M:%S %Z", localtime())
...
>     Date: Tue, 26 Jun 2001 23:40:46 Eastern Daylight Time
...
> seems like %Z in strftime should either return a +0500 or an EDT, no?

-0500, actually.

I think the Python documentation is incorrect in this case.  K&R only
describes %Z as "time zone name, if any", and the Single UNIX Spec is
just as vague:

    http://www.opengroup.org/onlinepubs/7908799/xsh/strftime.html

In any case, my time zone is one of "New Zealand Standard Time",
"Pacific/Auckland" or "NZST", none of which is listed in section 5.1
of RFC 822.  RFC 822 has been superseded by RFC 2822 now as well, and
the latter deprecates the named time zones.

Here's a function to return the correct numeric time zone for RFC 2822:

    def zone2822(timetuple):
        dst = timetuple[8]
        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."



Mon, 15 Dec 2003 18:33:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Trailing Zs in PIC

2. GAWK: strftime("%z") and portability (which version of strftime is used in compile?)

3. Localized strftime() output

4. unix time and strftime

5. strftime * date calculations

6. Q: inverse of strftime

7. strftime weirdness

8. strftime year

9. time.strftime BUG?

10. strftime ?

11. strftime and windows

12. bug in time.strftime on linux???

 

 
Powered by phpBB® Forum Software