[Datetime-SIG] Making tm_gmtoff and tm_zone available on all platforms
alexander.belopolsky at gmail.com
Tue Sep 29 03:21:51 CEST 2015
Most UNIX platforms extend struct tm to include tm_gmtoff and tm_zone
fields that contain the current UTC offset in seconds and the zone
Python has been making these fields available as attributes of
time.struct_time  since version 3.3, but only on platforms that support
them in the C library.
>>> import time
>>> t = time.localtime()
I propose that we make these attributes available on all platforms by
computing their values when they are not available in struct tm.
The tm_gmtoff value is easy to compute by comparing localtime() to gmtime():
>>> u = time.gmtime(time.mktime(t))
>>> from calendar import timegm
>>> timegm(t) - timegm(u)
and tm_zone can be computed by calling strftime() with a '%Z' directive.
>>> time.strftime('%Z', t)
What does the group think?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Datetime-SIG