简体   繁体   中英

Convert deprecated timezones php

I'm making the mapping of windows timezones to IANA, use this source https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml

But the problem is that for some of them there only IANA names from deprecated php list https://www.php.net/timezones.others

"Dateline Standard Time" "Etc/GMT+12"

 "Greenland Standard Time" "America/Godthab"

"India Standard Time" "Asia/Calcutta"

 "Nepal Standard Time" "Asia/Katmandu"

What would be the right alternatives for them?

The warnings at the top of the PHP "other time zones" page are reasonable with regard to a user or developer choosing a specific time zone for their application. However, the warnings are lacking context. Specifically:

  • All of the time zones listed on that page are still valid IANA time zone identifiers. They work now, and they will continue to work in the future.

  • Most of them are Link entries in the IANA database, which point at the current canonical Zone entry. For example, Asia/Calcutta is a link pointing at Asia/Kolkata . Either are valid and can be used in PHP and other systems.

  • With only a couple of rare exceptions, IANA zone names are never actually "deprecated", they are simply relegated to links and become non-canonical. I should have chosen better wording when I added that column to the Wikipedia table . (Yes, that was me. Perhaps I may update it.)

    • One rare exception is Canada/East-Saskatchewan , removed completely in IANA 2017c due to its long string length and rare usage. If you have this in your database, replace it with America/Regina .

    • The other rare exception is US/Pacific-New , removed completely in IANA 2020b because it created a lot of confusion. It was never a real time zone, but only a link. If you have this in your database, replace it with America/Los_Angeles .

  • The Etc/UTC is the canonical UTC zone. It should continue to be used when setting the default time zone on servers in most cases. It is not deprecated in any way.

  • The zones starting with Etc/GMT+ or Etc/GMT- are fixed-offset canonical zones for ships at sea in non-territorial waters. They are also sometimes used for other edge cases. They are not deprecated in any way. Their offsets are intentionally inverted ( Etc/GMT+12 = UTC-12).

With all of this in mind - you can simply use the results of the CLDR Windows zones mapping file directly. You don't need to do any additional translation of links to zones unless you are trying to deliver a canonical result.

Additionally - you likely don't need to write this code yourself. PHP's Internationalization Package can be installed by adding extension=php_intl.dll to your php.ini file. Then you can use functions like IntlTimeZone::getIDForWindowsID to perform the mapping. It uses the same CLDR file under the hood.

You could try to parse and map them from this file:

https://github.com/eggert/tz/blob/2017b/backward

Another option:

  1. Using https://wikitable2csv.ggor.de/ you could get csv file from this table: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones . I don't think that this data will be changed soon, so you could download it once and save in your project.

  2. If you look at status column you could see that there may be Canonical or Alias values.

  3. If this column is alias, you should fetch name of canonical timezone from Notes column. If the columns is canonical - that's it

  4. Filter result from duplicates

This way, I think you will not have empty values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM