<div dir="ltr">I had been wondering about that myself. But your implementation proposal sounds kind of expensive, doesn't it?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 28, 2015 at 6:21 PM, Alexander Belopolsky <span dir="ltr"><<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.<br><br>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.<div><br></div><div><div>>>> import time</div><div>>>> t = time.localtime()</div><div>>>> t.tm_gmtoff</div><div>-14400</div><div>>>> t.tm_zone</div><div>'EDT'</div><div><br></div><div>I propose that we make these attributes available on all platforms by computing their values when they are not available in struct tm.</div><div><br></div><div>The tm_gmtoff value is easy to compute by comparing localtime() to gmtime():</div><div><br></div><div><div>>>> u = time.gmtime(time.mktime(t))</div><div>>>> from calendar import timegm</div><div>>>> timegm(t) - timegm(u)</div><div>-14400</div></div><div><br></div><div>and tm_zone can be computed by calling strftime() with a '%Z' directive.</div><div><br></div><div><div>>>> time.strftime('%Z', t)</div><div>'EDT'</div></div><div><br></div><div>What does the group think?</div><br>[1]: <a href="https://docs.python.org/3/library/time.html#time.struct_time" target="_blank">https://docs.python.org/3/library/time.html#time.struct_time</a><br></div></div>
<br>_______________________________________________<br>
Datetime-SIG mailing list<br>
<a href="mailto:Datetime-SIG@python.org">Datetime-SIG@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/datetime-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/datetime-sig</a><br>
The PSF Code of Conduct applies to this mailing list: <a href="https://www.python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">https://www.python.org/psf/codeofconduct/</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>