This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, brian.curtin, docs@python, georg.brandl, napik, techtonik
Date 2010-06-05.18:09:45
SpamBayes Score 0.050514787
Marked as misclassified No
Message-id <>
In-reply-to <>
On Sat, Jun 5, 2010 at 1:24 PM, anatoly techtonik
<> 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
        return -time.timezone

> 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

> 2. Should we at least group these timezone variables?

The come from existing C library practice.  POSIX defines tzname[2],
timezone, and daylight.

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 -

These variables are already grouped in tzinfo API.  What is missing is
method to get concrete tzinfo implementation in stdlib.  See
Date User Action Args
2010-06-05 18:09:47belopolskysetrecipients: + belopolsky, georg.brandl, techtonik, brian.curtin, napik, docs@python
2010-06-05 18:09:45belopolskylinkissue7229 messages
2010-06-05 18:09:45belopolskycreate