Skip to content
Merged
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
18 changes: 10 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DateTimeKind GetCorrespondingKind(TimeZoneInfo? timeZone)
// We check reference equality to see if 'this' is the same as
// TimeZoneInfo.Local or TimeZoneInfo.Utc. This check is needed to
// support setting the DateTime Kind property to 'Local' or
// 'Utc' on the ConverTime(...) return value.
// 'Utc' on the ConvertTime(...) return value.
//
// Using reference equality instead of value equality was a
// performance based design compromise. The reference equality
Expand Down Expand Up @@ -1011,9 +1011,9 @@ private TimeZoneInfo(

_id = id;
_baseUtcOffset = baseUtcOffset;
_displayName = displayName ?? string.Empty;
_standardDisplayName = standardDisplayName ?? string.Empty;
_daylightDisplayName = disableDaylightSavingTime ? string.Empty : daylightDisplayName ?? string.Empty;
_displayName = displayName;
_standardDisplayName = standardDisplayName;
_daylightDisplayName = disableDaylightSavingTime ? null : daylightDisplayName;
_supportsDaylightSavingTime = adjustmentRulesSupportDst && !disableDaylightSavingTime;
_adjustmentRules = adjustmentRules;

Expand All @@ -1031,10 +1031,12 @@ public static TimeZoneInfo CreateCustomTimeZone(
{
bool hasIanaId = TryConvertIanaIdToWindowsId(id, allocate: false, out _);

standardDisplayName ??= string.Empty;

return new TimeZoneInfo(
id,
baseUtcOffset,
displayName,
displayName ?? string.Empty,
standardDisplayName,
standardDisplayName,
adjustmentRules: null,
Expand Down Expand Up @@ -1085,9 +1087,9 @@ public static TimeZoneInfo CreateCustomTimeZone(
return new TimeZoneInfo(
id,
baseUtcOffset,
displayName,
standardDisplayName,
daylightDisplayName,
displayName ?? string.Empty,
standardDisplayName ?? string.Empty,
daylightDisplayName ?? string.Empty,
adjustmentRules,
disableDaylightSavingTime,
hasIanaId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,32 @@ public static void LocalTzIsNotUtc()
Assert.NotEqual(TimeZoneInfo.Utc.StandardName, TimeZoneInfo.Local.StandardName);
}

private static bool SupportICUAndRemoteExecution => PlatformDetection.IsIcuGlobalization && RemoteExecutor.IsSupported;

[InlineData("Pacific Standard Time")]
[InlineData("America/Los_Angeles")]
[ConditionalTheory(nameof(SupportICUAndRemoteExecution))]
public static void TestZoneNamesUsingAlternativeId(string zoneId)
{
RemoteExecutor.Invoke(id =>
{
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(id);
Assert.False(string.IsNullOrEmpty(tzi.StandardName), $"StandardName for '{id}' is null or empty.");
Assert.False(string.IsNullOrEmpty(tzi.DaylightName), $"DaylightName for '{id}' is null or empty.");
Assert.False(string.IsNullOrEmpty(tzi.DisplayName), $"DisplayName for '{id}' is null or empty.");
}, zoneId).Dispose();
}

[Fact]
public static void TestCustomTimeZonesWithNullNames()
{
TimeZoneInfo custom = TimeZoneInfo.CreateCustomTimeZone("Custom Time Zone With Null Names", TimeSpan.FromHours(-8), null, null);
Assert.Equal("Custom Time Zone With Null Names", custom.Id);
Assert.Equal(string.Empty, custom.StandardName);
Assert.Equal(string.Empty, custom.DaylightName);
Assert.Equal(string.Empty, custom.DisplayName);
}

private static bool IsEnglishUILanguage => CultureInfo.CurrentUICulture.Name.Length == 0 || CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en";

private static bool IsEnglishUILanguageAndRemoteExecutorSupported => IsEnglishUILanguage && RemoteExecutor.IsSupported;
Expand Down