<Compile Include="$(CommonPath)Interop\Interop.TimeZoneDisplayNameType.cs">
<Link>Common\Interop\Interop.TimeZoneDisplayNameType.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)Interop\Interop.TimeZoneInfo.cs" Condition="'$(TargetsBrowser)' != 'true'">
+ <Compile Include="$(CommonPath)Interop\Interop.TimeZoneInfo.cs">
<Link>Common\Interop\Interop.TimeZoneInfo.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Interop.Utils.cs">
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Browser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Browser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Browser.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.GetDisplayName.Invariant.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.GetDisplayName.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsOSXLike)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.libobjc.cs">
bool[] StandardTime;
bool[] GmtTime;
string? futureTransitionsPosixFormat;
+ string? standardAbbrevName = null;
+ string? daylightAbbrevName = null;
// parse the raw TZif bytes; this method can throw ArgumentException when the data is malformed.
TZif_ParseRaw(data, out t, out dts, out typeOfLocalTime, out transitionType, out zoneAbbreviations, out StandardTime, out GmtTime, out futureTransitionsPosixFormat);
if (!transitionType[type].IsDst)
{
_baseUtcOffset = transitionType[type].UtcOffset;
- _standardDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
+ standardAbbrevName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
}
else
{
- _daylightDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
+ daylightAbbrevName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
}
}
if (!transitionType[i].IsDst)
{
_baseUtcOffset = transitionType[i].UtcOffset;
- _standardDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
+ standardAbbrevName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
}
else
{
- _daylightDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
+ daylightAbbrevName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
}
}
}
+
+ // Use abbrev as the fallback
+ _standardDisplayName = standardAbbrevName;
+ _daylightDisplayName = daylightAbbrevName;
_displayName = _standardDisplayName;
string uiCulture = CultureInfo.CurrentUICulture.Name.Length == 0 ? FallbackCultureName : CultureInfo.CurrentUICulture.Name; // ICU doesn't work nicely with Invariant
Assert.NotNull(utc.ToString());
}
+ // Due to ICU size limitations, full daylight/standard names are not included.
+ // name abbreviations, if available, are used instead
+ public static IEnumerable<object []> Platform_TimeZoneNamesTestData()
+ {
+ if (PlatformDetection.IsBrowser)
+ return new TheoryData<TimeZoneInfo, string, string, string>
+ {
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strPacific), "(UTC-08:00) PST", "PST", "PDT" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strSydney), "(UTC+10:00) AEST", "AEST", "AEDT" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strPerth), "(UTC+08:00) AWST", "AWST", "AWDT" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strIran), "(UTC+03:30) +0330", "+0330", "+0430" },
+
+ { s_NewfoundlandTz, "(UTC-03:30) NST", "NST", "NDT" },
+ { s_catamarcaTz, "(UTC-03:00) -03", "-03", "-02" }
+ };
+ else
+ return new TheoryData<TimeZoneInfo, string, string, string>
+ {
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strPacific), "(UTC-08:00) Pacific Standard Time", "Pacific Standard Time", "Pacific Daylight Time" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strSydney), "(UTC+10:00) Australian Eastern Standard Time", "Australian Eastern Standard Time", "Australian Eastern Daylight Time" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strPerth), "(UTC+08:00) Australian Western Standard Time", "Australian Western Standard Time", "Australian Western Daylight Time" },
+ { TimeZoneInfo.FindSystemTimeZoneById(s_strIran), "(UTC+03:30) +0330", "+0330", "+0430" },
+
+ { s_NewfoundlandTz, "(UTC-03:30) NST", "NST", "NDT" },
+ { s_catamarcaTz, "(UTC-03:00) -03", "-03", "-02" }
+ };
+ }
+
+ [Theory]
+ [MemberData(nameof(Platform_TimeZoneNamesTestData))]
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ public static void Platform_TimeZoneNames(TimeZoneInfo tzi, string displayName, string standardName, string daylightName)
+ {
+ if (PlatformDetection.IsBrowser)
+ {
+ // Console.WriteLine($"DisplayName: {tzi.DisplayName}, StandardName: {tzi.StandardName}, DaylightName: {tzi.DaylightName}");
+ Assert.Equal($"DisplayName: {tzi.DisplayName}, StandardName: {tzi.StandardName}, DaylightName: {tzi.DaylightName}",
+ $"DisplayName: {displayName}, StandardName: {standardName}, DaylightName: {daylightName}");
+ }
+ }
+
[Fact]
public static void ConvertTime()
{