stub42/pytz

Wrong ISO timezone offset for all timezone starts with "Etc/GMT"

nglehuy opened this issue · 1 comments

Description

Wrong timezone offset when printing isoformat of localized datetime for all timezones starts with "Etc/GMT" (Etc/GMT-1, Etc/GMT+1, ...)

Timezone offset of +07:00 of Etc/GMT+7 is printed as -07:00 (supposed to be printed as +07:00)

Reproduce code:

>>> import pytz
>>> from datetime import datetime
>>> now = datetime.now()
>>> now
datetime.datetime(2021, 12, 3, 16, 47, 48, 208044)
>>> dt_local = pytz.timezone("Asia/Ho_Chi_Minh").localize(now)
>>> dt_local.isoformat()
'2021-12-03T16:47:48.208044+07:00'
>>> dt_local = pytz.timezone("Etc/GMT+7").localize(now)
>>> dt_local.isoformat()
'2021-12-03T16:47:48.208044-07:00'
>>> dt_local = pytz.timezone("Etc/GMT-1").localize(now)
>>> dt_local.isoformat()
'2021-12-03T16:47:48.208044+01:00'

Version

pytz==2021.3

The Etc/GMT+XX and Etc/GMT-XX have the opposite sign due to backwards compatibility with POSIX. See the following for more explanations:

You can find many other articles on the web by searching for something like "timezone GMT reversed".