Re: [Datetime-SIG] Making tm_gmtoff and tm_zone available on all platforms
I had been wondering about that myself. But your implementation proposal sounds kind of expensive, doesn't it? On Mon, Sep 28, 2015 at 6:21 PM, Alexander Belopolsky < alexander.belopolsky@gmail.com> wrote:
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
_______________________________________________ Datetime-SIG mailing list Datetime-SIG@python.org https://mail.python.org/mailman/listinfo/datetime-sig The PSF Code of Conduct applies to this mailing list: https://www.python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)
participants (1)
-
Guido van Rossum