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

noreply@sourceforge.net noreply@sourceforge.net
Thu, 31 Jan 2002 01:33:33 -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: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Greg Ward (gward)
>Assigned to: M.-A. Lemburg (lemburg)
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?


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

>Comment By: M.-A. Lemburg (lemburg)
Date: 2002-01-31 01:33

Message:
Logged In: YES 
user_id=38388

Closing the report.

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

Comment By: M.-A. Lemburg (lemburg)
Date: 2002-01-29 09:44

Message:
Logged In: YES 
user_id=38388

The time integer you pass into strftime() doesn't carry 
along any timezone information, so strftime() has to
make some assumption as to what it is dealing with.

The default assumption naturally is local time and
that's what strftime() uses. Time zones simply don't
work with non-local times.

I'd suggest to close this as 'not a bug'.

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

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