@@ -84,7 +84,8 @@ public static IDictionary<string, string> GetTimeZonesForCountry(string countryC
84
84
Id = x ,
85
85
Name = GetNames ( x , langKey , false ) . Generic
86
86
} )
87
- . ToDictionary ( x => x . Id , x => x . Name , StringComparer . OrdinalIgnoreCase ) ;
87
+ . Where ( x => x . Name != null )
88
+ . ToDictionary ( x => x . Id , x => x . Name ! , StringComparer . OrdinalIgnoreCase ) ;
88
89
89
90
// Append city names only when needed to differentiate zones with the same name
90
91
foreach ( var group in results . GroupBy ( x => x . Value ) . Where ( x => x . Count ( ) > 1 ) . ToArray ( ) )
@@ -169,7 +170,7 @@ private static IDictionary<string, string> GetFixedTimeZoneNames(string language
169
170
170
171
foreach ( var zone in zones )
171
172
{
172
- var name = GetNames ( zone , langKey , abbreviations ) . Generic ;
173
+ var name = GetNames ( zone , langKey , abbreviations ) . Generic ! ;
173
174
results . Add ( zone , name ) ;
174
175
}
175
176
@@ -250,7 +251,7 @@ public static IDictionary<string, string> GetCountryNames(string languageCode)
250
251
/// <param name="timeZoneId">An IANA or Windows time zone identifier.</param>
251
252
/// <param name="languageCode">The IETF language tag (culture code) to use when localizing the display names.</param>
252
253
/// <returns>A display name associated with this time zone.</returns>
253
- public static string GetDisplayNameForTimeZone ( string timeZoneId , string languageCode )
254
+ public static string ? GetDisplayNameForTimeZone ( string timeZoneId , string languageCode )
254
255
{
255
256
var langKey = GetLanguageKey ( languageCode , true ) ;
256
257
if ( langKey == null )
@@ -265,8 +266,8 @@ public static string GetDisplayNameForTimeZone(string timeZoneId, string languag
265
266
return displayName ;
266
267
}
267
268
268
- if ( TZConvert . TryIanaToWindows ( timeZoneId , out timeZoneId ) &&
269
- displayNames . TryGetValue ( timeZoneId , out displayName ) )
269
+ if ( TZConvert . TryIanaToWindows ( timeZoneId , out var windowsTimeZoneId ) &&
270
+ displayNames . TryGetValue ( windowsTimeZoneId , out displayName ) )
270
271
{
271
272
return displayName ;
272
273
}
@@ -287,7 +288,7 @@ public static IDictionary<string, string> GetDisplayNames(string languageCode, b
287
288
{
288
289
throw new ArgumentException ( "Invalid Language Code" , nameof ( languageCode ) ) ;
289
290
}
290
-
291
+
291
292
var displayNames = Data . DisplayNames [ langKey ]
292
293
. Where ( x => ! TimeZoneData . ObsoleteWindowsZones . Contains ( x . Key ) )
293
294
. ToList ( ) ;
@@ -374,7 +375,7 @@ private static string GetLanguageKey(string languageCode, bool forDisplayNames =
374
375
}
375
376
}
376
377
377
- private static string GetLanguageSubkey ( string languageKey )
378
+ private static string ? GetLanguageSubkey ( string languageKey )
378
379
{
379
380
var keyParts = languageKey . Split ( '_' ) ;
380
381
if ( keyParts . Length == 1 )
@@ -387,10 +388,11 @@ private static string GetLanguageSubkey(string languageKey)
387
388
388
389
private static void SearchLanguages ( string languageKey , TimeZoneValues values , Action < string > action )
389
390
{
390
- while ( languageKey != null && ( values . Generic == null || values . Standard == null || values . Daylight == null ) )
391
+ var langKey = languageKey ;
392
+ while ( langKey != null && ( values . Generic == null || values . Standard == null || values . Daylight == null ) )
391
393
{
392
- action ( languageKey ) ;
393
- languageKey = GetLanguageSubkey ( languageKey ) ;
394
+ action ( langKey ) ;
395
+ langKey = GetLanguageSubkey ( langKey ) ;
394
396
}
395
397
}
396
398
@@ -401,15 +403,16 @@ private static string GetCldrCanonicalId(string timeZoneId)
401
403
402
404
private static string GetCityName ( string timeZoneId , string languageKey )
403
405
{
404
- while ( languageKey != null )
406
+ var langKey = languageKey ;
407
+ while ( langKey != null )
405
408
{
406
- var data = Data . CldrLanguageData [ languageKey ] ;
409
+ var data = Data . CldrLanguageData [ langKey ] ;
407
410
if ( data . CityNames . TryGetValue ( timeZoneId , out var cityName ) )
408
411
{
409
412
return cityName ;
410
413
}
411
414
412
- languageKey = GetLanguageSubkey ( languageKey ) ;
415
+ langKey = GetLanguageSubkey ( langKey ) ;
413
416
}
414
417
415
418
return timeZoneId . Split ( '/' ) . Last ( ) . Replace ( "_" , " " ) ;
@@ -526,7 +529,7 @@ private static TimeZoneValues GetNames(string timeZoneId, string languageKey, bo
526
529
}
527
530
}
528
531
529
- string regionName = null ;
532
+ string ? regionName = null ;
530
533
if ( country != null )
531
534
{
532
535
SearchLanguages ( languageKey , values , key =>
@@ -620,12 +623,12 @@ private static TimeZoneValues GetNames(string timeZoneId, string languageKey, bo
620
623
return values ;
621
624
}
622
625
623
- private static string GetMetazone ( string timeZoneId )
626
+ private static string ? GetMetazone ( string timeZoneId )
624
627
{
625
628
return Data . CldrMetazones . TryGetValue ( timeZoneId , out var metaZone ) ? metaZone : null ;
626
629
}
627
630
628
- private static bool PopulateDirectValues ( string langKey , TimeZoneValues values , string timeZoneId , string metaZone ,
631
+ private static bool PopulateDirectValues ( string langKey , TimeZoneValues values , string timeZoneId , string ? metaZone ,
629
632
bool abbreviations )
630
633
{
631
634
if ( ! Data . CldrLanguageData . ContainsKey ( langKey ) )
0 commit comments