Olson time zone to windows

1.2k views Asked by At

I need to convert a time zone from olson time zone in windows. Using PHP.

I found this http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml

It seems that it is not difficult to convert using this data.

But there are questions:

1) Can I trust this source?

2) How parse type with multi values:

<mapZone other="Eastern Standard Time" territory="US" type="America/New_York America/Detroit America/Indiana/Petersburg America/Indiana/Vincennes America/Indiana/Winamac America/Kentucky/Monticello America/Louisville"/>

Divided by space character?

  • America/New_York
  • America/Detroit
  • America/Indiana/Petersburg
  • America/Indiana/Vincennes
  • America/Indiana/Winamac
  • America/Kentucky/Monticello
  • America/Louisville

But why some zones have three components?

3) Always there when converting Olson time zone => Windows time zone will receive only 1 timezone or maybe more? And what to do in this case?

4) Are there any pitfalls? For example UTC.

1

There are 1 answers

0
Matt Johnson-Pint On BEST ANSWER

Yes, you can trust that source, and it is indeed the best source to use for this type of conversion. I have used the same data to implement the conversion functions for .NET.

Since your question is asking about PHP, I'll consider this not to be a duplicate question - though I'm curious why you want to do this in PHP, since PHP uses IANA/Olson time zones, even on Windows.

Windows time zones tend to be broader than IANA zones, thus explaining why multiple values exist in the mapping. The list is indeed separated by spaces, and the CLDR specs require that the first entry in the list be the canonical reference for the CLDR.

Why some zones have three components isn't related to CLDR, but these are actually the original zone identifiers. Wikipedia has a good explanation.

There is only a single identifier going from Olson to Windows - but not necessarily from Windows to Olson.

Yes, there are more pitfalls:

  • Not all IANA/Olson zones can be mapped to Windows zone ids. Example: America/Atikokan

  • CLDR and IANA disagree about what is canonical. CLDR canonical ids are never changed, while IANA canonical ids can indeed be changed, replacing the previous id with a link. This makes it a bit difficult to map from Olson to Windows, because you have to check all links.

    For example, India is Asia/Calcutta in the CLDR. It has been updated in the IANA tzdb to Asia/Kolkata - replacing Asia/Calcutta with a link. To map Asia/Kolkata to the Windows "India Standard Time", you have to check all links for the zone against the mappings.

  • CLDR maps Windows "UTC" zone to "Etc/GMT". IANA considers Etc/UTC (and other abbreviations) as a separate zone - not a link. So, you have to handle these manually.