Skip to content

Commit 3ed85ef

Browse files
MatTheCatnicolas-grekas
authored andcommitted
[Intl] Take timezoneTypes’ ianaMap into account
1 parent e8bb011 commit 3ed85ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+2526
-4
lines changed

src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TimezoneDataGenerator extends AbstractDataGenerator
3838
private array $zoneIds = [];
3939
private array $zoneToCountryMapping = [];
4040
private array $localeAliases = [];
41+
private array $ianaMap = [];
4142

4243
protected function scanLocales(LocaleScanner $scanner, string $sourceDir): array
4344
{
@@ -65,8 +66,14 @@ protected function preGenerate(): void
6566

6667
protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): ?array
6768
{
69+
if (!$this->ianaMap) {
70+
foreach ($reader->readEntry($tempDir, 'timezoneTypes', ['ianaMap', 'timezone']) as $cldr => $iana) {
71+
$this->ianaMap[str_replace(':', '/', $cldr)] = $iana;
72+
}
73+
}
74+
6875
if (!$this->zoneToCountryMapping) {
69-
$this->zoneToCountryMapping = self::generateZoneToCountryMapping($reader->read($tempDir, 'windowsZones'));
76+
$this->zoneToCountryMapping = $this->generateZoneToCountryMapping($reader->read($tempDir, 'windowsZones'));
7077
}
7178

7279
// Don't generate aliases, as they are resolved during runtime
@@ -77,7 +84,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
7784

7885
$localeBundle = $reader->read($tempDir, $displayLocale);
7986

80-
if (!isset($localeBundle['zoneStrings']) || null === $localeBundle['zoneStrings']) {
87+
if (!isset($localeBundle['zoneStrings'])) {
8188
return null;
8289
}
8390

@@ -222,6 +229,10 @@ private function generateZones(BundleEntryReaderInterface $reader, string $tempD
222229
}
223230

224231
$zones[$id] = $name;
232+
233+
if (isset($this->ianaMap[$id])) {
234+
$zones[$this->ianaMap[$id]] = $name;
235+
}
225236
}
226237

227238
return $zones;
@@ -242,14 +253,20 @@ private static function generateZoneMetadata(ArrayAccessibleResourceBundle $loca
242253
return $metadata;
243254
}
244255

245-
private static function generateZoneToCountryMapping(ArrayAccessibleResourceBundle $windowsZoneBundle): array
256+
private function generateZoneToCountryMapping(ArrayAccessibleResourceBundle $windowsZoneBundle): array
246257
{
247258
$mapping = [];
248259

249260
foreach ($windowsZoneBundle['mapTimezones'] as $zoneInfo) {
250261
foreach ($zoneInfo as $region => $zones) {
251262
if (RegionDataGenerator::isValidCountryCode($region)) {
252-
$mapping += array_fill_keys(explode(' ', $zones), $region);
263+
foreach (explode(' ', $zones) as $zone) {
264+
$mapping[$zone] = $region;
265+
266+
if (isset($this->ianaMap[$zone])) {
267+
$mapping[$this->ianaMap[$zone]] = $region;
268+
}
269+
}
253270
}
254271
}
255272
}

src/Symfony/Component/Intl/Resources/data/timezones/af.php

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/Intl/Resources/data/timezones/ak.php

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)