How to compare two timezones in python?

Example

 import pytz
 b=pytz.timezone('Europe/Rome')
 c=pytz.timezone('Europe/Berlin')

These two timezones have different names but represent the same thing, however

  • b==c returns false
  • b.zone is different than c.zone

Is there any way to see that b is in reality equal to c?

The concrete problem is that I have to convert the timezone of a pandas data frame, but only if this zone is different than let’s say c. The original timezone might be b and in this case I do not want to convert as it would be a lost of time to convert b into c (since they represent the same time zones at the end….)

Thanks for any help.

Update:
changed ‘CET’ into ‘Europe/Rome’ to make sure that the timezones are the same in the example, using the feedback from an answer

Best answer

It’s kind of ghetto, but I could compare the offsets of both timezones against a given a timestamp.

from datetime import datetime
today = datetime.today()
b.utcoffset(today) == c.utcoffset(today)