Timezones weirdness

Bug #91671 reported by Tristan Seligmann on 2007-03-12
This bug affects 3 people
Affects Status Importance Assigned to Milestone

Bug Description

>>> import pytz
>>> import datetime
>>> pytz.VERSION
>>> pytz.timezone('Africa/Johannesburg').utcoffset(datetime.datetime.now())
datetime.timedelta(0, 5400)
# This should be 7200 == 2 hours, not 1.5 hours; SAST has been UTC+2 for years now

>>> pytz.timezone('Etc/GMT+2').utcoffset(datetime.datetime.now())
datetime.timedelta(-1, 79200)
>>> pytz.timezone('Etc/GMT-2').utcoffset(datetime.datetime.now())
datetime.timedelta(0, 7200)
# These results seem to be swapped from what I would expect;
# GMT+2 should be 2 hours ahead of UTC, not 2 hours behind

Matt Good (launchpad-matt-good) wrote :

I can confirm that the GMT+2 and GMT-2 timezone offsets are still inverted in pytz 2007c. This affected Trac and I have currently monkey-patched the offsets from Trac if it sees that they're reversed.

See the comments at the end of the description from this bug report:

And here is the current monkey-patch:

Matt Good (launchpad-matt-good) wrote :

Ok, my fault. The naming convention of the GMT timezones is inverted from how the offsets are stored. So, the GMT+2 and -2 are correct.

Stuart Bishop (stub) wrote :

>>> dt = datetime(2007, 3, 11, 0, 0, 0)
>>> aj = pytz.timezone("Africa/Johannesburg")
>>> dt = aj.localize(dt, is_dst=True)
>>> dt.tzinfo.utcoffset(dt)
datetime.timedelta(0, 7200)

Until the tzinfo has been put into context, its behavior is undefined. Check out the README for details on constructing localized tzinfo instances. The api is somewhat different to what is documented in the Python reference.

The offsets for the legacy Etc/GMT* timezones is that way round because this is how it is in the source database. It is the wrong way around, but this is the way it has always been under Unix and changing this would break compatibility with other systems (which is also why it isn't fixed upstream). The Etc/* timezones are all deprecated and only there to support legacy systems and data if I recall correctly.

Changed in pytz:
status: Unconfirmed → Rejected
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers