Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 5518ab9

Browse files
authored
Fix Timezone Test with Morocco on Windows (#37419)
1 parent 10a014e commit 5518ab9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/System.Runtime/tests/System/TimeZoneInfoTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,12 +2221,23 @@ public static void TimeZoneInfo_DisplayNameStartsWithOffset()
22212221
{
22222222
Assert.False(string.IsNullOrWhiteSpace(tzi.StandardName));
22232223
Assert.Matches(@"^\(UTC(\+|-)[0-9]{2}:[0-9]{2}\) \S.*", tzi.DisplayName);
2224-
2224+
22252225
// see https://github.com/dotnet/corefx/pull/33204#issuecomment-438782500
22262226
if (PlatformDetection.IsNotWindowsNanoServer && !PlatformDetection.IsWindows7)
22272227
{
22282228
string offset = Regex.Match(tzi.DisplayName, @"(-|)[0-9]{2}:[0-9]{2}").Value;
2229-
Assert.True(tzi.BaseUtcOffset == TimeSpan.Parse(offset), $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.DisplayName}");
2229+
TimeSpan ts = TimeSpan.Parse(offset);
2230+
if (tzi.BaseUtcOffset != ts && tzi.Id.IndexOf("Morocco", StringComparison.Ordinal) >= 0)
2231+
{
2232+
// Windows data can report display name with UTC+01:00 offset which is not matching the actual BaseUtcOffset.
2233+
// We special case this in the test to avoid the test failures like:
2234+
// 01:00 != 00:00:00, dn:(UTC+01:00) Casablanca, sn:Morocco Standard Time
2235+
Assert.True(tzi.BaseUtcOffset == new TimeSpan(0, 0, 0), $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.StandardName}");
2236+
}
2237+
else
2238+
{
2239+
Assert.True(tzi.BaseUtcOffset == ts, $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.StandardName}");
2240+
}
22302241
}
22312242
}
22322243
}

0 commit comments

Comments
 (0)