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

Commit 9e38691

Browse files
committed
Fixing the TimeZoneInfo tests on Linux now that FindSystemTimeZoneById and Local are implemented.
The TimeZone Ids are different between Windows and Linux, so needed to adjust the tests to have the correct Id on each platform.
1 parent bbbf587 commit 9e38691

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

src/System.Runtime/tests/System.Runtime.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<Compile Include="System\ValueType.cs" />
8787
<Compile Include="System\Version.cs" />
8888
<Compile Include="System\WeakReference.cs" />
89+
<Compile Include="$(CommonPath)\Interop\Interop.PlatformDetection.cs">
90+
<Link>Common\Interop\Interop.PlatformDetection.cs</Link>
91+
</Compile>
8992
</ItemGroup>
9093
<ItemGroup>
9194
<None Include="project.json" />

src/System.Runtime/tests/System/TimeZoneInfo.cs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Runtime.InteropServices;
56
using Xunit;
67

78
public static class TimeZoneInfoTests
89
{
9-
private static String s_strPacific = "Pacific Standard Time";
10-
private static String s_strSydney = "AUS Eastern Standard Time";
11-
private static String s_strGMT = "GMT Standard Time";
12-
private static String s_strTonga = "Tonga Standard Time";
13-
private static String s_strBrasil = "E. South America Standard Time";
14-
private static String s_strPerth = "W. Australia Standard Time";
15-
private static String s_strBrasilia = "E. South America Standard Time";
16-
private static String s_strNairobi = "E. Africa Standard Time";
17-
private static String s_strAmsterdam = "W. Europe Standard Time";
10+
private static String s_strPacific = Interop.IsWindows ? "Pacific Standard Time" : "America/Los_Angeles";
11+
private static String s_strSydney = Interop.IsWindows ? "AUS Eastern Standard Time" : "Australia/Sydney";
12+
private static String s_strGMT = Interop.IsWindows ? "GMT Standard Time" : "Europe/London";
13+
private static String s_strTonga = Interop.IsWindows ? "Tonga Standard Time" : "Pacific/Tongatapu";
14+
private static String s_strBrasil = Interop.IsWindows ? "E. South America Standard Time" : "America/Sao_Paulo";
15+
private static String s_strPerth = Interop.IsWindows ? "W. Australia Standard Time" : "Australia/Perth";
16+
private static String s_strBrasilia = Interop.IsWindows ? "E. South America Standard Time" : "America/Sao_Paulo";
17+
private static String s_strNairobi = Interop.IsWindows ? "E. Africa Standard Time" : "Africa/Nairobi";
18+
private static String s_strAmsterdam = Interop.IsWindows ? "W. Europe Standard Time" : "Europe/Berlin";
19+
private static String s_strRussian = Interop.IsWindows ? "Russian Standard Time" : "Europe/Moscow";
20+
private static String s_strLibya = Interop.IsWindows ? "Libya Standard Time" : "Africa/Tripoli";
1821

1922
private static TimeZoneInfo s_myUtc = TimeZoneInfo.Utc;
2023
private static TimeZoneInfo s_myLocal = TimeZoneInfo.Local;
@@ -23,7 +26,7 @@ public static class TimeZoneInfoTests
2326
private static TimeZoneInfo s_nairobiTz = TimeZoneInfo.FindSystemTimeZoneById(s_strNairobi);
2427
private static TimeZoneInfo s_amsterdamTz = TimeZoneInfo.FindSystemTimeZoneById(s_strAmsterdam);
2528

26-
private static bool s_localIsPST = TimeZoneInfo.Local.StandardName == "Pacific Standard Time";
29+
private static bool s_localIsPST = TimeZoneInfo.Local.Id == s_strPacific;
2730
private static bool s_regLocalSupportsDST = s_regLocal.SupportsDaylightSavingTime;
2831
private static bool s_localSupportsDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;
2932

@@ -75,7 +78,7 @@ public static void ValidateLibyaTimeZoneTest()
7578
// Make sure first the timezone data is updated in the machine as it should include Libya Timezone
7679
try
7780
{
78-
tripoli = TimeZoneInfo.FindSystemTimeZoneById("Libya Standard Time");
81+
tripoli = TimeZoneInfo.FindSystemTimeZoneById(s_strLibya);
7982
}
8083
catch (Exception /* TimeZoneNotFoundException */ )
8184
{
@@ -96,7 +99,7 @@ public static void ValidateLibyaTimeZoneTest()
9699
[ActiveIssue(846, PlatformID.AnyUnix)]
97100
public static void ValidateRussiaTimeZoneTest()
98101
{
99-
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
102+
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(s_strRussian);
100103
var inputUtcDate = new DateTime(2013, 6, 1, 0, 0, 0, DateTimeKind.Utc);
101104

102105
DateTime russiaTime = TimeZoneInfo.ConvertTime(inputUtcDate, tz);
@@ -109,7 +112,6 @@ public static void ValidateRussiaTimeZoneTest()
109112
}
110113

111114
[Fact]
112-
[ActiveIssue(846, PlatformID.AnyUnix)]
113115
public static void ValidateExceptionsTest()
114116
{
115117
DateTimeOffset time1 = new DateTimeOffset(2006, 5, 12, 0, 0, 0, TimeSpan.Zero);
@@ -137,7 +139,6 @@ public static void ValidateExceptionsTest()
137139
}
138140

139141
[Fact]
140-
[ActiveIssue(846, PlatformID.AnyUnix)]
141142
public static void NearMinMaxDateTimeOffsetConvertTest()
142143
{
143144
VerifyConvert(DateTimeOffset.MaxValue, TimeZoneInfo.Utc.Id, DateTimeOffset.MaxValue);
@@ -159,15 +160,20 @@ public static void NearMinMaxDateTimeOffsetConvertTest()
159160
VerifyConvert(new DateTimeOffset(DateTime.MinValue.AddHours(5), new TimeSpan(-3, 0, 0)), s_strPacific, new DateTimeOffset(DateTime.MinValue, new TimeSpan(-8, 0, 0)));
160161

161162
VerifyConvert(DateTime.MaxValue, s_strPacific, s_strSydney, DateTime.MaxValue);
162-
VerifyConvert(DateTime.MaxValue.AddHours(-19), s_strPacific, s_strSydney, DateTime.MaxValue);
163+
if (Interop.IsWindows) // [ActiveIssue(846, PlatformID.AnyUnix)]
164+
{
165+
VerifyConvert(DateTime.MaxValue.AddHours(-19), s_strPacific, s_strSydney, DateTime.MaxValue);
166+
}
163167
VerifyConvert(DateTime.MaxValue.AddHours(-19.5), s_strPacific, s_strSydney, DateTime.MaxValue.AddHours(-0.5));
164168
VerifyConvert(DateTime.MinValue, s_strSydney, s_strPacific, DateTime.MinValue);
165-
VerifyConvert(DateTime.MinValue.AddHours(19), s_strSydney, s_strPacific, DateTime.MinValue);
166-
VerifyConvert(DateTime.MinValue.AddHours(19.5), s_strSydney, s_strPacific, DateTime.MinValue.AddHours(0.5));
169+
if (Interop.IsWindows) // [ActiveIssue(846, PlatformID.AnyUnix)]
170+
{
171+
VerifyConvert(DateTime.MinValue.AddHours(19), s_strSydney, s_strPacific, DateTime.MinValue);
172+
VerifyConvert(DateTime.MinValue.AddHours(19.5), s_strSydney, s_strPacific, DateTime.MinValue.AddHours(0.5));
173+
}
167174
}
168175

169176
[Fact]
170-
[ActiveIssue(846, PlatformID.AnyUnix)]
171177
public static void DateTimeOffsetVariousSystemTimeZonesTest()
172178
{
173179
var time1 = new DateTimeOffset(2006, 5, 12, 5, 17, 42, new TimeSpan(-7, 0, 0));
@@ -276,7 +282,6 @@ public static void DateTimeOffsetVariousSystemTimeZonesTest()
276282
}
277283

278284
[Fact]
279-
[ActiveIssue(846, PlatformID.AnyUnix)]
280285
public static void SameTimeZonesTest()
281286
{
282287
var time1 = new DateTimeOffset(2003, 10, 26, 3, 0, 1, new TimeSpan(-2, 0, 0));
@@ -454,7 +459,6 @@ public static void PerthRulesTest()
454459
}
455460

456461
[Fact]
457-
[ActiveIssue(846, PlatformID.AnyUnix)]
458462
public static void UtcToUtcTest()
459463
{
460464
var time1utc = new DateTime(2003, 3, 30, 0, 0, 23, DateTimeKind.Utc);
@@ -472,7 +476,6 @@ public static void UtcToUtcTest()
472476
}
473477

474478
[Fact]
475-
[ActiveIssue(846, PlatformID.AnyUnix)]
476479
public static void UtcToLocalTest()
477480
{
478481
if (s_localIsPST)
@@ -739,7 +742,6 @@ public static void LocalToUtcTest()
739742
}
740743

741744
[Fact]
742-
[ActiveIssue(846, PlatformID.AnyUnix)]
743745
public static void DtKindTest()
744746
{
745747
VerifyConvertException<ArgumentException>(new DateTime(2006, 2, 13, 5, 37, 48, DateTimeKind.Utc), s_strPacific, s_strSydney);
@@ -756,7 +758,6 @@ public static void DtKindTest()
756758
}
757759

758760
[Fact]
759-
[ActiveIssue(846, PlatformID.AnyUnix)]
760761
public static void MiscUtcTests()
761762
{
762763
VerifyConvert(new DateTime(2003, 4, 6, 1, 30, 0, DateTimeKind.Utc), "UTC", DateTime.SpecifyKind(new DateTime(2003, 4, 6, 1, 30, 0), DateTimeKind.Utc));
@@ -812,7 +813,6 @@ public static void MiscUtcTests()
812813
}
813814

814815
[Fact]
815-
[ActiveIssue(846, PlatformID.AnyUnix)]
816816
public static void BrasiliaTests()
817817
{
818818
var time1 = new DateTimeOffset(2003, 10, 26, 3, 0, 1, new TimeSpan(-2, 0, 0));
@@ -832,7 +832,6 @@ public static void BrasiliaTests()
832832
}
833833

834834
[Fact]
835-
[ActiveIssue(846, PlatformID.AnyUnix)]
836835
public static void TongaTests()
837836
{
838837
var time1 = new DateTime(2006, 5, 12, 5, 17, 42, DateTimeKind.Utc);
@@ -921,7 +920,6 @@ public static void ThrowOnAmbiguousOffsetsTests()
921920
}
922921

923922
[Fact]
924-
[ActiveIssue(846, PlatformID.AnyUnix)]
925923
public static void ThrowOnNairobiAmbiguousOffsetsTests()
926924
{
927925
VerifyAmbiguousOffsetsException<ArgumentException>(s_nairobiTz, new DateTime(2006, 1, 15, 7, 15, 23));
@@ -937,7 +935,6 @@ public static void ThrowOnNairobiAmbiguousOffsetsTests()
937935
}
938936

939937
[Fact]
940-
[ActiveIssue(846, PlatformID.AnyUnix)]
941938
public static void AmsterdamAmbiguousOffsetsTests()
942939
{
943940
//
@@ -1181,7 +1178,6 @@ public static void AmsterdamAmbiguousOffsetsTests()
11811178
}
11821179

11831180
[Fact]
1184-
[ActiveIssue(846, PlatformID.AnyUnix)]
11851181
public static void LocalAmbiguousOffsetsTests()
11861182
{
11871183
if (!s_localIsPST)
@@ -1221,7 +1217,6 @@ public static void LocalAmbiguousOffsetsTests()
12211217
}
12221218

12231219
[Fact]
1224-
[ActiveIssue(846, PlatformID.AnyUnix)]
12251220
public static void DstTests()
12261221
{
12271222
VerifyDST(TimeZoneInfo.Utc, new DateTime(2006, 1, 15, 7, 15, 23), false);
@@ -1424,7 +1419,6 @@ public static void DstTests()
14241419
}
14251420

14261421
[Fact]
1427-
[ActiveIssue(846, PlatformID.AnyUnix)]
14281422
public static void InvalidTimeTests()
14291423
{
14301424
VerifyInv(TimeZoneInfo.Utc, new DateTime(2006, 1, 15, 7, 15, 23), false);

0 commit comments

Comments
 (0)