The following test passes on Windows but fails on Unix:
public static IEnumerable<object[]> SystemTimeZonesTestData()
{
foreach (TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
{
yield return new object[] { tz };
}
}
[Theory]
[MemberData(nameof(SystemTimeZonesTestData))]
public static void ToSerializedString_FromSerializedString_RoundTrips(TimeZoneInfo timeZone)
{
string serialized = timeZone.ToSerializedString();
TimeZoneInfo deserializedTimeZone = TimeZoneInfo.FromSerializedString(serialized);
Assert.Equal(timeZone, deserializedTimeZone);
Assert.Equal(serialized, deserializedTimeZone.ToSerializedString());
}
I believe it's due to how GetAdjustmentRules is implemented on Unix: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Unix.cs#L131-L153
vs. on Windows: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Win32.cs#L87
See dotnet/corefx#14795
Also, when you pass an AdjustmentRule[] array to TimeZoneInfo.CreateCustomTimeZone to create a custom instance of TimeZoneInfo, calling GetAdjustmentRules on Windows will always give you a cloned copy of the same adjustment rules, whereas on Unix it looks like it will modify the adjustment rules that are returned.
The following test passes on Windows but fails on Unix:
I believe it's due to how
GetAdjustmentRulesis implemented on Unix: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Unix.cs#L131-L153vs. on Windows: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Win32.cs#L87
See dotnet/corefx#14795
Also, when you pass an
AdjustmentRule[]array toTimeZoneInfo.CreateCustomTimeZoneto create a custom instance ofTimeZoneInfo, callingGetAdjustmentRuleson Windows will always give you a cloned copy of the same adjustment rules, whereas on Unix it looks like it will modify the adjustment rules that are returned.