[Python-ideas] Reduce platform dependence of date and time related functions
Alexander Belopolsky
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])
else:
tz = timezone(delta)
http://hg.python.org/cpython/file/default/Lib/datetime.py#l1500
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130917/4cc57058/attachment-0001.html>
More information about the Python-ideas
mailing list