Making tm_gmtoff and tm_zone available on all platforms
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 abbreviation. Python has been making these fields available as attributes of time.struct_time [1] since version 3.3, but only on platforms that support them in the C library.
import time t = time.localtime() t.tm_gmtoff -14400 t.tm_zone 'EDT'
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) -14400
and tm_zone can be computed by calling strftime() with a '%Z' directive.
time.strftime('%Z', t) 'EDT'
What does the group think? [1]: https://docs.python.org/3/library/time.html#time.struct_time
participants (1)
-
Alexander Belopolsky