@@ -38,6 +38,7 @@ class TimezoneDataGenerator extends AbstractDataGenerator
38
38
private array $ zoneIds = [];
39
39
private array $ zoneToCountryMapping = [];
40
40
private array $ localeAliases = [];
41
+ private array $ ianaMap = [];
41
42
42
43
protected function scanLocales (LocaleScanner $ scanner , string $ sourceDir ): array
43
44
{
@@ -65,8 +66,14 @@ protected function preGenerate(): void
65
66
66
67
protected function generateDataForLocale (BundleEntryReaderInterface $ reader , string $ tempDir , string $ displayLocale ): ?array
67
68
{
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
+
68
75
if (!$ this ->zoneToCountryMapping ) {
69
- $ this ->zoneToCountryMapping = self :: generateZoneToCountryMapping ($ reader ->read ($ tempDir , 'windowsZones ' ));
76
+ $ this ->zoneToCountryMapping = $ this -> generateZoneToCountryMapping ($ reader ->read ($ tempDir , 'windowsZones ' ));
70
77
}
71
78
72
79
// Don't generate aliases, as they are resolved during runtime
@@ -77,7 +84,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
77
84
78
85
$ localeBundle = $ reader ->read ($ tempDir , $ displayLocale );
79
86
80
- if (!isset ($ localeBundle ['zoneStrings ' ]) || null === $ localeBundle [ ' zoneStrings ' ] ) {
87
+ if (!isset ($ localeBundle ['zoneStrings ' ])) {
81
88
return null ;
82
89
}
83
90
@@ -222,6 +229,10 @@ private function generateZones(BundleEntryReaderInterface $reader, string $tempD
222
229
}
223
230
224
231
$ zones [$ id ] = $ name ;
232
+
233
+ if (isset ($ this ->ianaMap [$ id ])) {
234
+ $ zones [$ this ->ianaMap [$ id ]] = $ name ;
235
+ }
225
236
}
226
237
227
238
return $ zones ;
@@ -242,14 +253,20 @@ private static function generateZoneMetadata(ArrayAccessibleResourceBundle $loca
242
253
return $ metadata ;
243
254
}
244
255
245
- private static function generateZoneToCountryMapping (ArrayAccessibleResourceBundle $ windowsZoneBundle ): array
256
+ private function generateZoneToCountryMapping (ArrayAccessibleResourceBundle $ windowsZoneBundle ): array
246
257
{
247
258
$ mapping = [];
248
259
249
260
foreach ($ windowsZoneBundle ['mapTimezones ' ] as $ zoneInfo ) {
250
261
foreach ($ zoneInfo as $ region => $ zones ) {
251
262
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
+ }
253
270
}
254
271
}
255
272
}
0 commit comments