[Python-bugs-list] [ python-Bugs-510218 ] strftime() gets timezone wrong

noreply@sourceforge.net noreply@sourceforge.net
Tue, 29 Jan 2002 08:28:52 -0800


Bugs item #510218, was opened at 2002-01-29 08:28
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=510218&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Ward (gward)
Assigned to: Nobody/Anonymous (nobody)
Summary: strftime() gets timezone wrong

Initial Comment:
Platform: Debian Linux (sid/unstable)
          glibc 2.2.4
          Python 2.2

Python's time.strftime() gets the timezone wrong 
in various creative ways.  The timezone variable 
is set correctly:

>>> time.timezone
18000

(That's 5 hours behind UTC, which is correct.)

However, the %z and %Z format codes are 
inconsistent, and one or the other is always wrong:

>>> time.strftime("%H:%M %z (%Z)", 
time.localtime(time.time()))
'11:25 +0000 (EST)'
>>> time.strftime("%H:%M %z (%Z)", 
time.gmtime(time.time()))
'16:25 +0000 (EST)'

%z seems to ignore the fact that I'm not in UTC;
%Z is the opposite.

Note that the "date" command (from GNU shellutils 
2.0.11) gets it right in both cases:

$ date +"%H:%M:%S %z (%Z)"
11:27:18 -0500 (EST)
$ date --utc +"%H:%M:%S %z (%Z)"
16:27:20 +0000 (UTC)

The obvious next step is to write a little C 
program to see if libc or Python is broken -- ie. 
is the "date" command doing special magic here?


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

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