Convert IANA timezones to Windows

The IANA timezones database is probably the most used standard to reference a timezone by name (a lot of libraries use it).

The problem comes when you need to use these timezones informations in a C# program: Windows timezones have different names and there’s no standard method to convert a IANA timezone to a Windows one.

Informations about the relation between IANA and Windows timezones  are accessible here:
https://github.com/unicode-org/cldr/blob/master/common/supplemental/windowsZones.xmlhttp://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml

Looking at the data is clear that you can convert from a IANA timezone to a Windows one, but a Windows timezone cannot be converted to a single IANA timezone. This is because Windows groups more than one timezone under the same name.

<supplementalData>
	<version number="$Revision$"/>
	<windowsZones>
		<mapTimezones otherVersion="7e00100" typeVersion="2016d">
			...
			<!-- (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna -->
			<mapZone other="W. Europe Standard Time" territory="001" type="Europe/Berlin"/>
			<mapZone other="W. Europe Standard Time" territory="AD" type="Europe/Andorra"/>
			<mapZone other="W. Europe Standard Time" territory="AT" type="Europe/Vienna"/>
			<mapZone other="W. Europe Standard Time" territory="CH" type="Europe/Zurich"/>
			<mapZone other="W. Europe Standard Time" territory="DE" type="Europe/Berlin Europe/Busingen"/>
			<mapZone other="W. Europe Standard Time" territory="GI" type="Europe/Gibraltar"/>
			<mapZone other="W. Europe Standard Time" territory="IT" type="Europe/Rome"/>
			<mapZone other="W. Europe Standard Time" territory="LI" type="Europe/Vaduz"/>
			<mapZone other="W. Europe Standard Time" territory="LU" type="Europe/Luxembourg"/>
			<mapZone other="W. Europe Standard Time" territory="MC" type="Europe/Monaco"/>
			<mapZone other="W. Europe Standard Time" territory="MT" type="Europe/Malta"/>
			<mapZone other="W. Europe Standard Time" territory="NL" type="Europe/Amsterdam"/>
			<mapZone other="W. Europe Standard Time" territory="NO" type="Europe/Oslo"/>
			<mapZone other="W. Europe Standard Time" territory="SE" type="Europe/Stockholm"/>
			<mapZone other="W. Europe Standard Time" territory="SJ" type="Arctic/Longyearbyen"/>
			<mapZone other="W. Europe Standard Time" territory="SM" type="Europe/San_Marino"/>
			<mapZone other="W. Europe Standard Time" territory="VA" type="Europe/Vatican"/>
			...
		</mapTimezones>
	</windowsZones>

</supplementalData>

I made a test project to demonstrate how to convert timezones: just deserialize the data and look for the corresponding timezone.

IANA timezone   : Europe/Rome
Windows timezone: W. Europe Standard Time

IANA timezone   : Pacific/Tongatapu
Windows timezone: Tonga Standard Time

You can download the test project here: IANATimezonesConverter.zip

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.