[Datetime-SIG] Making tm_gmtoff and tm_zone available on all platforms
Guido van Rossum
guido at python.org
Tue Sep 29 05:04:31 CEST 2015
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 at 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
> 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()
> >>> t.tm_gmtoff
> >>> t.tm_zone
> 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
> >>> 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?
> : https://docs.python.org/3/library/time.html#time.struct_time
> Datetime-SIG mailing list
> Datetime-SIG at python.org
> The PSF Code of Conduct applies to this mailing list:
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Datetime-SIG