[Python-bugs-list] [ python-Bugs-437041 ] strfime %Z isn't an RFC 822 timezone

noreply@sourceforge.net noreply@sourceforge.net
Thu, 28 Jun 2001 04:19:29 -0700


Bugs item #437041, was opened at 2001-06-28 04:19
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=437041&group_id=5470

Category: Documentation
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Carey Evans (carey)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: strfime %Z isn't an RFC 822 timezone

Initial Comment:
The section in the library reference manual for the
time module says, under strftime:

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

And goes on to use %Z with localtime().  However, %Z
for me returns "NZST" and may return a full description
under other OSes.  RFC 822 only lists a few
abbreviations as valid, and NZST isn't one of them.

In addition, RFC 822 has now been obsoleted by RFC
2822, which deprecates the use of abbreviations for
time zones.

To generate an RFC 2822 date string, you can either use
gmtime():

    strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

or do a bit of math:

    t = localtime()
    dst = t[8]
    offs = (timezone, timezone, altzone)[1 + dst]
    zstr = "%+.2d%.2d" % (offs / -3600, abs(offs / 60)
% 60)
    print strftime("%a, %d %b %Y %H:%M:%S ", t) + zstr

Also note that these only work if the LC_TIME locale
category hasn't been set to a non-English locale.

Maybe "%Y-%m-%d %H:%M:%S" would be a better example,
for an ISO8601 formatted time?


On a positive note, RFC 2822 defines a year as four
digits, so the footnote could be updated.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=437041&group_id=5470