Reputation: 13930
My data is stored with a timestamp in Greenwich Mean Time (GMT):
import pandas as pd
import pytz
# data is stored in UTC
timestamp_utc = pd.Timestamp('2018-1-18 23:00', tz='Etc/GMT')
print(timestamp_utc)
2018-01-18 23:00:00+00:00
Now I would like to view my data in Central European Time (CET), which has a fixed offset of +1 hour to GMT.
# Central European Time (CET)
cet_tz = pytz.timezone('Etc/GMT+1')
timestamp_cet = timestamp_utc.astimezone(cet_tz)
print(timestamp_cet)
2018-01-18 22:00:00-01:00
This is very confusing for me, I would have expected 2018-01-19 00:00:00+01:00
.
In the documentation the following is mentioned on fixed offsets:
Fixed offsets
The 'Etc/GMT*' time zones mentioned above provide fixed offset specifications, but watch out for the counter-intuitive sign convention.
Can anybody explain what this means? Does it really mean, that if I want Etc/GMT+1
I have to do Etc/GMT-1
?
Since:
print(timestamp_utc.astimezone(pytz.timezone('Etc/GMT-1')))
Results in the expecting:
2018-01-19 00:00:00+01:00
Can anyone explain the logic of this counter-intuitive behavior?
EDIT
I thought I could use pytz.timezone('CET')
for Central European Time. But this maps to CEST during DST in summer (UTC+2:00
) and is therefor not suitable for usage as a true CET timezone. Moreover, the timezone CET
is also deprecated.
So, Etc/GMT-1
is the canonical way of representing true Central European Time (UTC+01:00
).
Upvotes: 0
Views: 421
Reputation: 241959
The Etc/GMT*
zones are designed to be POSIX compliant for backwards compatibility with TZ
environment variables on systems that don't have a full time zone database installed. POSIX time zone rules have the sign of the offset inverted from the ISO 8601 standard that we generally expect.
This is explained in the comments in the tz database:
Be consistent with POSIX TZ settings in the Zone names, even though this is the opposite of what many people expect. POSIX has positive signs west of Greenwich, but many people expect positive signs east of Greenwich. For example, TZ='Etc/GMT+4' uses the abbreviation "-04" and corresponds to 4 hours behind UT (i.e. west of Greenwich) even though many people would expect it to mean 4 hours ahead of UT (i.e. east of Greenwich).
It is also described on Wikipedia:
The special area of "Etc" is used for some administrative zones, particularly for "Etc/UTC" which represents Coordinated Universal Time. In order to conform with the POSIX style, those zone names beginning with "Etc/GMT" have their sign reversed from the standard ISO 8601 convention. In the "Etc" area, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead of GMT.)
In general, for inhabited locations on land, you should prefer using location-based zone identifiers instead. For example, use Europe/Amsterdam
for time in the Netherlands. This has the advantage of properly switching between CET and CEST at the correct points in time, as well as any prior historical transitions.
Reserve using Etc/GMT*
zones for edge cases like tracking time for ships at sea.
You can view a full list of tzdb zone names here.
Upvotes: 2