pythontimezoneidentityzoneinfo

How do I determine whether a ZoneInfo is an alias?


I am having trouble identifying whether a ZoneInfo is built with an alias:

> a = ZoneInfo('Atlantic/Faeroe')
> b = ZoneInfo('Atlantic/Faroe')
> a == b
False

It seems like these ZoneInfos are identical in practice. How do I identify that they are the same, as opposed to e.g. EST and UTC which are different?


Solution

  • The tzdata package publishes the data for the IANA time zone database.

    If installed, one could compare the data files for those zones located in:

    <PYTHON_DIR>\Lib\site-packages\tzdata\zoneinfo\Atlantic
    

    The data files for Faeroe and Faroe compare as binary same.

    Programmatically, the binary data can be directly read and compared:

    from importlib import resources
    
    with resources.open_binary('tzdata.zoneinfo.Atlantic', 'Faroe') as f:
        data1 = f.read()
    with resources.open_binary('tzdata.zoneinfo.Atlantic', 'Faeroe') as f:
        data2 = f.read()
    
    print(data1 == data2)  # True
    

    Ref: https://tzdata.readthedocs.io/en/latest/#examples

    There is also the file <PYTHON_DIR>\Lib\site-packages\tzdata\zoneinfo\tzdata.zi which is a text representation of the IANA database, and contains the line:

    L Atlantic/Faroe Atlantic/Faeroe
    

    An L line means Link LINK_FROM LINK_TO to define an alias. This indicates that Atlantic/Faeroe is an alias for the Atlantic/Faroe time zone defined earlier in the file.