mapping joda timezone to windows timezone (for exa

2019-07-15 04:54发布

I'm having trouble mapping joda time zones to windows time zones.

I use the xml of CLDR mappings, and it works for most of the translations.

nevertheless, it doesn't have values for several joda time zones:

America/Indiana/Indianapolis, BST, Australia/Victoria, Universal, Australia/NSW, America/Fort_Wayne, Africa/Asmara, America/Kentucky/Louisville, Asia/Kashgar, US/Pacific, Australia/West, Australia/Queensland, Australia/South, US/Eastern, US/Central, US/Arizona, Australia/Tasmania, NZ, US/Mountain, Australia/Eucla, GMT, Japan, CAT, Etc/GMT+0, CST, PST, EST, Australia/Canberra, Mexico/General, Israel, Canada/Eastern, Etc/GMT+9, Canada/Central, Australia/North

Where can I find the mapping between these joda timezones to windows timezones?

1条回答
爷、活的狠高调
2楼-- · 2019-07-15 05:29

Using pure CLDR data:

  • Check for the zone in the /common/bcp47/timezone.xml file.

    If it's not the first entry in the alias field, then use the first entry. Example:

    <type name="aumel" description="Melbourne, Australia"
                       alias="Australia/Melbourne Australia/Victoria"/>
    

    You can see Australia/Victoria as the second item, so it is an alias to Australia/Melbourne. Note that CLDR's canonical zones are not exactly matched to TZDB's definition of canonical, so use these CLDR mappings - not the link entries from tzdb.

  • Now check the /common/supplemental/windowsZones.xml file. Example:

    <mapZone other="AUS Eastern Standard Time" territory="AU"
             type="Australia/Sydney Australia/Melbourne"/>
    

    The type field contains one or more tzdb zones. The other field contains the corresponding Windows zone.

  • Be aware that not all tzdb zones have a valid corresponding Windows zone, and some are not perfect mappings.

    • Example of imperfect mapping: America/Havana => Eastern Standard Time

      • DST transition days align, but Cuba transitions at midnight instead of 2 AM
    • Example of unmappable zone: Australia/Lord_Howe

      • Exists in timezone.xml, but not in windowsZones.xml.
      • There is currently no Windows time zone entry for this location.
  • You have a few items in your list (BST, CAT, CST, PST) that are not valid tzdb zones, even by Joda-Time's list. These could be abbreviations or rule names, but they are not zone identifiers.

查看更多
登录 后发表回答