[Python-ideas] Reduce platform dependence of date and time related functions
alexander.belopolsky at gmail.com
Tue Sep 17 23:21:27 CEST 2013
On Tue, Sep 17, 2013 at 4:58 PM, <random832 at fastmail.us> wrote:
> 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.
How is this different from what we do in datetime.astimezone()?
# Compute UTC offset and compare with the value implied
# by tm_isdst. If the values match, use the zone name
# implied by tm_isdst.
delta = local - datetime(*_time.gmtime(ts)[:6])
dst = _time.daylight and localtm.tm_isdst > 0
gmtoff = -(_time.altzone if dst else _time.timezone)
if delta == timedelta(seconds=gmtoff):
tz = timezone(delta, _time.tzname[dst])
tz = timezone(delta)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas