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

Commit 021dfe7

Browse files
author
Eric Erhardt
committed
Fix TimeZoneInfo tests on Linux.
Now that TimeZoneInfo is correctly parsing and creating adjustment rules on Linux, remove all [ActiveIssue] attributes in the TimeZoneInfo tests and make them pass on Linux. There are a few cases where Windows and Linux rules differ. For instance, Linux will use local mean time for DateTimes before standard time came into affect. Also, there are some Australia time zones that changed rules that Windows couldn't/didn't support.
1 parent 39fb86f commit 021dfe7

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

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

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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;
65
using Xunit;
76

87
public static class TimeZoneInfoTests
@@ -31,6 +30,9 @@ public static class TimeZoneInfoTests
3130
private static bool s_regLocalSupportsDST = s_regLocal.SupportsDaylightSavingTime;
3231
private static bool s_localSupportsDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;
3332

33+
// In 2006, Australia delayed ending DST by a week. However, Windows says it still ended the last week of March.
34+
private static readonly int s_sydneyOffsetLastWeekOfMarch2006 = Interop.IsWindows ? 10 : 11;
35+
3436
[Fact]
3537
public static void TestKind()
3638
{
@@ -94,7 +96,6 @@ public static void ValidateLibyaTimeZoneTest()
9496
}
9597

9698
[Fact]
97-
[ActiveIssue(2465, PlatformID.AnyUnix)]
9899
public static void ValidateRussiaTimeZoneTest()
99100
{
100101
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(s_strRussian);
@@ -158,17 +159,22 @@ public static void NearMinMaxDateTimeOffsetConvertTest()
158159
VerifyConvert(new DateTimeOffset(DateTime.MinValue.AddHours(5), new TimeSpan(-3, 0, 0)), s_strPacific, new DateTimeOffset(DateTime.MinValue, new TimeSpan(-8, 0, 0)));
159160

160161
VerifyConvert(DateTime.MaxValue, s_strPacific, s_strSydney, DateTime.MaxValue);
161-
if (s_isWindows) // [ActiveIssue(2465, PlatformID.AnyUnix)]
162-
{
163162
VerifyConvert(DateTime.MaxValue.AddHours(-19), s_strPacific, s_strSydney, DateTime.MaxValue);
164-
}
165163
VerifyConvert(DateTime.MaxValue.AddHours(-19.5), s_strPacific, s_strSydney, DateTime.MaxValue.AddHours(-0.5));
164+
166165
VerifyConvert(DateTime.MinValue, s_strSydney, s_strPacific, DateTime.MinValue);
167-
if (s_isWindows) // [ActiveIssue(2465, PlatformID.AnyUnix)]
166+
if (s_isWindows)
168167
{
169168
VerifyConvert(DateTime.MinValue.AddHours(19), s_strSydney, s_strPacific, DateTime.MinValue);
170169
VerifyConvert(DateTime.MinValue.AddHours(19.5), s_strSydney, s_strPacific, DateTime.MinValue.AddHours(0.5));
171170
}
171+
else
172+
{
173+
// for early times, IANA uses local mean time (LMT), which is based on the solar time.
174+
// The Pacific Standard Time LMT is UTC-07:53. For Sydney, LMT is UTC+10:04.
175+
VerifyConvert(DateTime.MinValue.AddHours(17).AddMinutes(57), s_strSydney, s_strPacific, DateTime.MinValue);
176+
VerifyConvert(DateTime.MinValue.AddHours(17.5).AddMinutes(57), s_strSydney, s_strPacific, DateTime.MinValue.AddHours(0.5));
177+
}
172178
}
173179

174180
[Fact]
@@ -315,7 +321,6 @@ public static void SameTimeZonesTest()
315321
}
316322

317323
[Fact]
318-
[ActiveIssue(846, PlatformID.AnyUnix)]
319324
public static void NearMinMaxDateTimeConvertTest()
320325
{
321326
DateTime time1 = new DateTime(2006, 5, 12);
@@ -327,13 +332,25 @@ public static void NearMinMaxDateTimeConvertTest()
327332
VerifyConvert(utcMaxValue, s_strPacific, DateTime.MaxValue.AddHours(-8));
328333
DateTime utcMinValue = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
329334
VerifyConvert(utcMinValue, s_strPacific, DateTime.MinValue);
335+
336+
if (Interop.IsWindows)
337+
{
330338
VerifyConvert(utcMinValue.AddHours(8), s_strPacific, DateTime.MinValue);
331339
VerifyConvert(utcMinValue.AddHours(8.5), s_strPacific, DateTime.MinValue.AddHours(0.5));
332340
VerifyConvert(utcMinValue, s_strSydney, DateTime.MinValue.AddHours(11));
333341
}
342+
else
343+
{
344+
// for early times, IANA uses local mean time (LMT), which is based on the solar time.
345+
// The Pacific Standard Time LMT is UTC-07:53.
346+
VerifyConvert(utcMinValue.AddHours(8).AddMinutes(-7), s_strPacific, DateTime.MinValue);
347+
VerifyConvert(utcMinValue.AddHours(8.5).AddMinutes(-7), s_strPacific, DateTime.MinValue.AddHours(0.5));
348+
// For Sydney, LMT is UTC+10:04.
349+
VerifyConvert(utcMinValue, s_strSydney, DateTime.MinValue.AddHours(10).AddMinutes(4));
350+
}
351+
}
334352

335353
[Fact]
336-
[ActiveIssue(846, PlatformID.AnyUnix)]
337354
public static void DateTimeVariousSystemTimeZonesTest()
338355
{
339356
var time1utc = new DateTime(2006, 5, 12, 5, 17, 42, DateTimeKind.Utc);
@@ -345,7 +362,7 @@ public static void DateTimeVariousSystemTimeZonesTest()
345362
time1utc = new DateTime(2006, 3, 28, 9, 47, 12, DateTimeKind.Utc);
346363
time1 = new DateTime(2006, 3, 28, 9, 47, 12);
347364
VerifyConvert(time1utc, s_strPacific, time1.AddHours(-8));
348-
VerifyConvert(time1utc, s_strSydney, time1.AddHours(10));
365+
VerifyConvert(time1utc, s_strSydney, time1.AddHours(s_sydneyOffsetLastWeekOfMarch2006));
349366
time1utc = new DateTime(2006, 11, 5, 1, 3, 0, DateTimeKind.Utc);
350367
time1 = new DateTime(2006, 11, 5, 1, 3, 0);
351368
VerifyConvert(time1utc, s_strPacific, time1.AddHours(-8));
@@ -382,8 +399,8 @@ public static void DateTimeVariousSystemTimeZonesTest()
382399
VerifyConvert(time1, s_strPacific, s_strSydney, time1.AddHours(17));
383400
VerifyConvert(time1, s_strSydney, s_strPacific, time1.AddHours(-17));
384401
time1 = new DateTime(2006, 3, 28, 9, 47, 12);
385-
VerifyConvert(time1, s_strPacific, s_strSydney, time1.AddHours(18));
386-
VerifyConvert(time1, s_strSydney, s_strPacific, time1.AddHours(-18));
402+
VerifyConvert(time1, s_strPacific, s_strSydney, time1.AddHours(s_sydneyOffsetLastWeekOfMarch2006 + 8));
403+
VerifyConvert(time1, s_strSydney, s_strPacific, time1.AddHours(-(s_sydneyOffsetLastWeekOfMarch2006 + 8)));
387404
time1 = new DateTime(2006, 11, 5, 1, 3, 0);
388405
VerifyConvert(time1, s_strPacific, s_strSydney, time1.AddHours(19));
389406
VerifyConvert(time1, s_strSydney, s_strPacific, time1.AddHours(-19));
@@ -393,7 +410,6 @@ public static void DateTimeVariousSystemTimeZonesTest()
393410
}
394411

395412
[Fact]
396-
[ActiveIssue(846, PlatformID.AnyUnix)]
397413
public static void PerthRulesTest()
398414
{
399415
var time1utc = new DateTime(2005, 12, 31, 15, 59, 59, DateTimeKind.Utc);
@@ -424,11 +440,20 @@ public static void PerthRulesTest()
424440
time1utc = new DateTime(2006, 11, 30, 18, 0, 0, DateTimeKind.Utc);
425441
time1 = new DateTime(2006, 12, 1, 2, 0, 0);
426442
VerifyConvert(time1utc, s_strPerth, time1);
427-
// ambiguous time between rules
428-
// this is not ideal, but the way it works
443+
429444
time1utc = new DateTime(2006, 12, 31, 15, 59, 59, DateTimeKind.Utc);
430445
time1 = new DateTime(2006, 12, 31, 15, 59, 59);
446+
if (Interop.IsWindows)
447+
{
448+
// ambiguous time between rules
449+
// this is not ideal, but the way it works
431450
VerifyConvert(time1utc, s_strPerth, time1.AddHours(8));
451+
}
452+
else
453+
{
454+
// Linux has the correct rules for Perth for days from December 3, 2006 to the end of the year
455+
VerifyConvert(time1utc, s_strPerth, time1.AddHours(9));
456+
}
432457

433458
// 2007 rule
434459
time1utc = new DateTime(2006, 12, 31, 20, 1, 2, DateTimeKind.Utc);
@@ -512,7 +537,6 @@ public static void UtcToLocalTest()
512537
}
513538

514539
[Fact]
515-
[ActiveIssue(846, PlatformID.AnyUnix)]
516540
public static void LocalToSystemTest()
517541
{
518542
var time1 = new DateTime(2006, 5, 12, 5, 17, 42);
@@ -522,13 +546,16 @@ public static void LocalToSystemTest()
522546
VerifyConvert(time1local, s_strSydney, time1.Subtract(localOffset).AddHours(10));
523547
VerifyConvert(time1, s_strPacific, time1.Subtract(localOffset).AddHours(-7));
524548
VerifyConvert(time1local, s_strPacific, time1.Subtract(localOffset).AddHours(-7));
549+
525550
time1 = new DateTime(2006, 3, 28, 9, 47, 12);
526551
time1local = new DateTime(2006, 3, 28, 9, 47, 12, DateTimeKind.Local);
527552
localOffset = TimeZoneInfo.Local.GetUtcOffset(time1);
528-
VerifyConvert(time1, s_strSydney, time1.Subtract(localOffset).AddHours(10));
529-
VerifyConvert(time1local, s_strSydney, time1.Subtract(localOffset).AddHours(10));
553+
VerifyConvert(time1, s_strSydney, time1.Subtract(localOffset).AddHours(s_sydneyOffsetLastWeekOfMarch2006));
554+
VerifyConvert(time1local, s_strSydney, time1.Subtract(localOffset).AddHours(s_sydneyOffsetLastWeekOfMarch2006));
555+
530556
VerifyConvert(time1, s_strPacific, time1.Subtract(localOffset).AddHours(-8));
531557
VerifyConvert(time1local, s_strPacific, time1.Subtract(localOffset).AddHours(-8));
558+
532559
time1 = new DateTime(2006, 11, 5, 1, 3, 0);
533560
time1local = new DateTime(2006, 11, 5, 1, 3, 0, DateTimeKind.Local);
534561
localOffset = TimeZoneInfo.Local.GetUtcOffset(time1);
@@ -603,7 +630,6 @@ public static void LocalToSystemTest()
603630
}
604631

605632
[Fact]
606-
[ActiveIssue(846, PlatformID.AnyUnix)]
607633
public static void LocalToLocalTest()
608634
{
609635
if (s_localIsPST)
@@ -662,7 +688,6 @@ public static void LocalToLocalTest()
662688
}
663689

664690
[Fact]
665-
[ActiveIssue(846, PlatformID.AnyUnix)]
666691
public static void LocalToUtcTest()
667692
{
668693
var time1 = new DateTime(1964, 6, 19, 12, 45, 10);

0 commit comments

Comments
 (0)