2

Given an IANA time zone ID, such as "America/New_York" or "Europe/Lisbon", how can I obtain the corresponding BCP-47 time zone ID, such as "usnyc" or "ptlis", using ICU4C?

These values are required to generate Unicode BCP-47 Locale IDs with extensions, e.g. 'en-US-u-fw-mon-hc-h23-tz-usnyc".

kpozin
  • 25,691
  • 19
  • 57
  • 76
  • You mean the `"name"` field? Why do you want that? AFAIK, they aren't used much outside that one file. There is some info [in the spec](https://www.unicode.org/reports/tr35/tr35.html#Time_Zone_Identifiers) about how and why they are defined, but other than that they should probably not leak out of CLDR. – Matt Johnson-Pint Jun 03 '19 at 23:25
  • Added clarification. These values are part of the Unicode BCP-47 Locale Identifier spec. – kpozin Jun 05 '19 at 01:48
  • Locales and time zones are orthogonal concepts. I find it odd that tz codes would be ever used in a locale string, even with bcp47 extensions. I think this is one case where the spec is unclear and/or overreaching. I'd be really interested in knowing more about the use case, or an implementation that honors them. For that matter, how are they intend to be applied? The spec doesn't really say, as far as I can tell. – Matt Johnson-Pint Jun 05 '19 at 03:09
  • In other words, if I have a date and time value that represents the local time in `Asia/Shanghai`, what would *displaying it* in `en-US-u-tz-usnyc` do? Convert it? What about APIs that take both a locale and time zone? Which would take precedence? – Matt Johnson-Pint Jun 05 '19 at 03:17
  • Or more concerning, what if I just have an unspecified date and time. Maybe it's from `Asia/Shanghai` or `Europe/Paris` or my local time zone or UTC. Time zone conversion requires understanding of both source and target. It seems like a time zone code in a locale string would only represent a target if it was involved in conversion. Or is it just there to *assert* that the dates and times are in that time zone? But then again, what if they aren't? Or what if there are multiple from different time zones? It's all too confusing when you mix time zones into locales. – Matt Johnson-Pint Jun 05 '19 at 18:48
  • By analogy with Noda Time, you would only use the locale's time zone when formatting an `Instant`. It would be an error to use it when formatting a `LocalDateTime`, an `OffsetDateTime`, or a `ZonedDateTime`, unless you made some questionable assumptions (for `LocalDateTime` and `OffsetDateTime`) or applied a conversion (for `ZonedDateTime`). – kpozin Jun 07 '19 at 01:32

0 Answers0