[issue19502] Wrong time zone offset, when using time.strftime() with a given struct_time

Paweł Wroniszewski report at bugs.python.org
Tue Nov 5 10:01:32 CET 2013


New submission from Paweł Wroniszewski:

I encountered the problem in logging module, but it is broader then that. Have a look at the following code:

====
import time
DATE_FORMAT = '%d/%b/%Y %H:%M:%S%z %Z'
print(time.strftime(DATE_FORMAT))
print(time.strftime(DATE_FORMAT,time.localtime()))
====

The first print statement prints the correct time zone offset (in the place of %z), while the second prints +0000. It is important, because the logging module passes a predifined time_struct to time.strftime to format it - the timezone offset is not usable in such case. 

The documentation for time.strftime(format[, t]) reads:
"If t is not provided, the current time as returned by localtime() is used"
but apparently there must be something extra going on under the hood.

I checked that the problem is present in Python 2.7 and 3.2, probably in other version as well. Maybe it is platform dependent - I use Ubuntu 12.04 64 bit. 

If you want to change the time zone for testing, just run e.g.:
===
import os
os.environ['TZ'] = 'Asia/Kolkata'
import time
time.tzset()
===

----------
messages: 202200
nosy: pwronisz
priority: normal
severity: normal
status: open
title: Wrong time zone offset, when using time.strftime() with a given struct_time
type: behavior
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19502>
_______________________________________


More information about the Python-bugs-list mailing list