[Python-ideas] Reduce platform dependence of date and time related functions

random832 at fastmail.us random832 at fastmail.us
Tue Sep 17 22:58:17 CEST 2013

On Tue, Sep 17, 2013, at 9:31, Victor Stinner wrote:
> 2013/9/17  <random832 at fastmail.us>:
> > I have an addition to this proposal: struct_time should always provide
> > tm_gmtoff and tm_zone, gmtime should populate them with 0 and GMT*, and
> > if the platform does not provide values localtime should populate them
> > with timezone or altzone and values from tzname depending on if isdst is
> > true after calling the platform localtime function.
> In Python, "unknown" is usually written None. It's safer than filling
> the structure with invalid values.

They're not unknown. The values are provided by the system in global
variables. If timezone, altzone, and tzname should not be used, then
they should not be provided.

You can also determine gmtoff empirically by calling timegm and
subtracting the original timestamp from the result. Or you could look at
the seconds, minutes, hours, year, and yday members after calling both
gmtime and localtime in the first place.

More information about the Python-ideas mailing list