Is %z broken for return values of time.gmtime()?

Michael Schwarz michi.schwarz at gmail.com
Mon Sep 16 09:15:22 EDT 2013


I’m wondering whether this is expected:

Python 3.3.2 (default, May 21 2013, 11:50:47) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%F %T %z", time.gmtime(40 * 365 * 86400))
'2009-12-22 00:00:00 +0100‘

According to the documentation of time.gmtime(), it returns a struct_time in UTC, but %z is replaced by +0100, which is the UTC offset of my OS’s time zone without DST, but DST is currently in effect here (but was not at the timestamp passed to gmtime()).

40 * 365 * 86400 seconds is a bit less than 40 Years. I’m using a date near to today to rule out any peculiarities with dates that are long in the past. Using a date at which DST was active yields the same result:

>>> time.strftime("%F %T %z", time.gmtime(40.5 * 365 * 86400))
'2010-06-22 12:00:00 +0100'

Why is my OS’s time zone used for formatting a struct_time with the UTC time zone? I’m running OS X 10.8.4, my OS’s time zone is set to CET/CEST.

Regards
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2227 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20130916/b3288045/attachment.bin>


More information about the Python-list mailing list