Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:
On Sat, Jun 5, 2010 at 1:24 PM, anatoly techtonik <rep...@bugs.python.org> wrote: .. > So, to answer a question "What is the current UTC offset?" you need to: > if time.daylight: > if time.altzone: # using only if defined > use time.altzone > else: > use time.timezone > else: > use time.timezone > No, if time.daylight is non-zero, you still need to check the current value of tm_isdst from localtime(). Here is how bzr reportedly handles this: def local_time_offset(t=None): """Return offset of local zone from GMT, either at present or at time t.""" # python2.3 localtime() can't take None if t is None: t = time.time() if time.localtime(t).tm_isdst and time.daylight: return -time.altzone else: return -time.timezone http://blogs.gnome.org/jamesh/2006/12/31/python-timetimezone-timealtzone-edge-case/ > 1. Is that really works like described above? That works for current time, but subject to race condition twice a year. You should get time and dst indormation from the same localtime() call. For problems with arbitrary time t, see the link above. > 2. Should we at least group these timezone variables? > The come from existing C library practice. POSIX defines tzname[2], timezone, and daylight. http://www.opengroup.org/onlinepubs/009695399/basedefs/time.h.html altzone is a popular non-standard addition which is strictly redundant. Since POSIX does not define anything about daylight variable other than it has to be zero when DST is not in effect, compliant implementations can define is so that altzone = timezone - daylight. These variables are already grouped in tzinfo API. What is missing is method to get concrete tzinfo implementation in stdlib. See issue5094. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7229> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com