Skip to content

[Intl] Take timezoneTypes’ ianaMap into account #61426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
private array $zoneIds = [];
private array $zoneToCountryMapping = [];
private array $localeAliases = [];
private array $ianaMap = [];

protected function scanLocales(LocaleScanner $scanner, string $sourceDir): array
{
Expand Down Expand Up @@ -64,8 +65,14 @@

protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): ?array
{
if (!$this->ianaMap) {
foreach ($reader->readEntry($tempDir, 'timezoneTypes', ['ianaMap', 'timezone']) as $cldr => $iana) {
$this->ianaMap[str_replace(':', '/', $cldr)] = $iana;

Check failure on line 70 in src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidPropertyAssignmentValue

src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php:70:17: InvalidPropertyAssignmentValue: $this->ianaMap with declared type 'array<array-key, mixed>' cannot be assigned type 'non-empty-array<array<array-key, string>|string, mixed>' (see https://psalm.dev/145)

Check failure on line 70 in src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidPropertyAssignmentValue

src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php:70:17: InvalidPropertyAssignmentValue: $this->ianaMap with declared type 'array<array-key, mixed>' cannot be assigned type 'non-empty-array<array<array-key, string>|string, mixed>' (see https://psalm.dev/145)
}
}

if (!$this->zoneToCountryMapping) {
$this->zoneToCountryMapping = self::generateZoneToCountryMapping($reader->read($tempDir, 'windowsZones'));
$this->zoneToCountryMapping = $this->generateZoneToCountryMapping($reader->read($tempDir, 'windowsZones'));
}

// Don't generate aliases, as they are resolved during runtime
Expand All @@ -76,7 +83,7 @@

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

if (!isset($localeBundle['zoneStrings']) || null === $localeBundle['zoneStrings']) {
if (!isset($localeBundle['zoneStrings'])) {
return null;
}

Expand Down Expand Up @@ -217,6 +224,10 @@
}

$zones[$id] = $name;

if (isset($this->ianaMap[$id])) {
$zones[$this->ianaMap[$id]] = $name;
}
}

return $zones;
Expand All @@ -237,14 +248,20 @@
return $metadata;
}

private static function generateZoneToCountryMapping(ArrayAccessibleResourceBundle $windowsZoneBundle): array
private function generateZoneToCountryMapping(ArrayAccessibleResourceBundle $windowsZoneBundle): array
{
$mapping = [];

foreach ($windowsZoneBundle['mapTimezones'] as $zoneInfo) {
foreach ($zoneInfo as $region => $zones) {
if (RegionDataGenerator::isValidCountryCode($region)) {
$mapping += array_fill_keys(explode(' ', $zones), $region);
foreach (explode(' ', $zones) as $zone) {
$mapping[$zone] = $region;

if (isset($this->ianaMap[$zone])) {
$mapping[$this->ianaMap[$zone]] = $region;
}
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Intl/Resources/data/timezones/af.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/Symfony/Component/Intl/Resources/data/timezones/ak.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading