|
| 1 | +--- |
| 2 | +title: Countries and Zones |
| 3 | +--- |
| 4 | + |
| 5 | +Moment Timezone's [country-related APIs](/timezone/docs/#/using-timezones/getting-country-zones/) rely on known associations between zones and countries, which come directly from the IANA tzdb (see [Data Source](#/data-calculations/data-source/)). |
| 6 | + |
| 7 | +The mapping of zones to countries exposes a subtle nuance in the tzdb structure that doesn't match a lot of people's mental model of the data. |
| 8 | +This can sometimes catch out users who see something unexpected in the country data and assume it must be a bug. |
| 9 | + |
| 10 | +The key principle is that zone identifiers like `Europe/Berlin` and `Asia/Tokyo` are **labels** for regions of the world where the clocks have agreed since 1970. |
| 11 | +These regions are not specifically tied to a single country, and can span multiple countries if needed. |
| 12 | +This would be equally true if the labels didn't have city names at all, but instead were named something like `Europe/Zone073`. |
| 13 | +The city name is simply an aid to users to make the database more human-readable. |
| 14 | + |
| 15 | +The tzdb defines which countries use each time zone. |
| 16 | +But because the zones are named after cities, this can be easily misinterpreted to mean that a city is in multiple countries, which is incorrect. |
| 17 | + |
| 18 | +As an example, let's look at a line from the source [`zone1970.tab`](https://data.iana.org/time-zones/data/zone1970.tab): |
| 19 | + |
| 20 | +``` |
| 21 | +CZ,SK +5005+01426 Europe/Prague |
| 22 | +``` |
| 23 | + |
| 24 | +This line is **not** indicating that the city of Prague is in both Czechia and Slovakia. |
| 25 | +It is saying that a time zone region—where clocks have agreed since 1970—can be used in both Czechia and Slovakia, and happens to have the _label_ of `Europe/Prague`. |
| 26 | + |
| 27 | +Moment Timezone also includes the backwards-compatibility data listed in the older (and deprecated) [`zone.tab`](https://data.iana.org/time-zones/data/zone.tab). |
| 28 | +This includes the line: |
| 29 | + |
| 30 | +``` |
| 31 | +SK +4809+01707 Europe/Bratislava |
| 32 | +``` |
| 33 | + |
| 34 | +The `Europe/Bratislava` zone is an alias of `Europe/Prague`, so there's no difference in the processed time zone data. |
| 35 | + |
| 36 | +All this means that the results from Moment Timezone's country APIs can give some seemingly-unintuitive results that are correct according to the data model: |
| 37 | + |
| 38 | +```js |
| 39 | +moment.tz.zonesForCountry('CZ'); // ["Europe/Prague"] |
| 40 | +moment.tz.zonesForCountry('SK'); // ["Europe/Bratislava", "Europe/Prague"] |
| 41 | + |
| 42 | +moment.tz.zone('Europe/Bratislava').countries(); // ["SK"] |
| 43 | +moment.tz.zone('Europe/Prague').countries(); // ["CZ", "SK"] |
| 44 | +``` |
0 commit comments