2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System ;
5
- using System . Runtime . InteropServices ;
6
5
using Xunit ;
7
6
8
7
public static class TimeZoneInfoTests
@@ -31,6 +30,9 @@ public static class TimeZoneInfoTests
31
30
private static bool s_regLocalSupportsDST = s_regLocal . SupportsDaylightSavingTime ;
32
31
private static bool s_localSupportsDST = TimeZoneInfo . Local . SupportsDaylightSavingTime ;
33
32
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
+
34
36
[ Fact ]
35
37
public static void TestKind ( )
36
38
{
@@ -94,7 +96,6 @@ public static void ValidateLibyaTimeZoneTest()
94
96
}
95
97
96
98
[ Fact ]
97
- [ ActiveIssue ( 2465 , PlatformID . AnyUnix ) ]
98
99
public static void ValidateRussiaTimeZoneTest ( )
99
100
{
100
101
TimeZoneInfo tz = TimeZoneInfo . FindSystemTimeZoneById ( s_strRussian ) ;
@@ -158,17 +159,22 @@ public static void NearMinMaxDateTimeOffsetConvertTest()
158
159
VerifyConvert ( new DateTimeOffset ( DateTime . MinValue . AddHours ( 5 ) , new TimeSpan ( - 3 , 0 , 0 ) ) , s_strPacific , new DateTimeOffset ( DateTime . MinValue , new TimeSpan ( - 8 , 0 , 0 ) ) ) ;
159
160
160
161
VerifyConvert ( DateTime . MaxValue , s_strPacific , s_strSydney , DateTime . MaxValue ) ;
161
- if ( s_isWindows ) // [ActiveIssue(2465, PlatformID.AnyUnix)]
162
- {
163
162
VerifyConvert ( DateTime . MaxValue . AddHours ( - 19 ) , s_strPacific , s_strSydney , DateTime . MaxValue ) ;
164
- }
165
163
VerifyConvert ( DateTime . MaxValue . AddHours ( - 19.5 ) , s_strPacific , s_strSydney , DateTime . MaxValue . AddHours ( - 0.5 ) ) ;
164
+
166
165
VerifyConvert ( DateTime . MinValue , s_strSydney , s_strPacific , DateTime . MinValue ) ;
167
- if ( s_isWindows ) // [ActiveIssue(2465, PlatformID.AnyUnix)]
166
+ if ( s_isWindows )
168
167
{
169
168
VerifyConvert ( DateTime . MinValue . AddHours ( 19 ) , s_strSydney , s_strPacific , DateTime . MinValue ) ;
170
169
VerifyConvert ( DateTime . MinValue . AddHours ( 19.5 ) , s_strSydney , s_strPacific , DateTime . MinValue . AddHours ( 0.5 ) ) ;
171
170
}
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
+ }
172
178
}
173
179
174
180
[ Fact ]
@@ -315,7 +321,6 @@ public static void SameTimeZonesTest()
315
321
}
316
322
317
323
[ Fact ]
318
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
319
324
public static void NearMinMaxDateTimeConvertTest ( )
320
325
{
321
326
DateTime time1 = new DateTime ( 2006 , 5 , 12 ) ;
@@ -327,13 +332,25 @@ public static void NearMinMaxDateTimeConvertTest()
327
332
VerifyConvert ( utcMaxValue , s_strPacific , DateTime . MaxValue . AddHours ( - 8 ) ) ;
328
333
DateTime utcMinValue = DateTime . SpecifyKind ( DateTime . MinValue , DateTimeKind . Utc ) ;
329
334
VerifyConvert ( utcMinValue , s_strPacific , DateTime . MinValue ) ;
335
+
336
+ if ( Interop . IsWindows )
337
+ {
330
338
VerifyConvert ( utcMinValue . AddHours ( 8 ) , s_strPacific , DateTime . MinValue ) ;
331
339
VerifyConvert ( utcMinValue . AddHours ( 8.5 ) , s_strPacific , DateTime . MinValue . AddHours ( 0.5 ) ) ;
332
340
VerifyConvert ( utcMinValue , s_strSydney , DateTime . MinValue . AddHours ( 11 ) ) ;
333
341
}
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
+ }
334
352
335
353
[ Fact ]
336
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
337
354
public static void DateTimeVariousSystemTimeZonesTest ( )
338
355
{
339
356
var time1utc = new DateTime ( 2006 , 5 , 12 , 5 , 17 , 42 , DateTimeKind . Utc ) ;
@@ -345,7 +362,7 @@ public static void DateTimeVariousSystemTimeZonesTest()
345
362
time1utc = new DateTime ( 2006 , 3 , 28 , 9 , 47 , 12 , DateTimeKind . Utc ) ;
346
363
time1 = new DateTime ( 2006 , 3 , 28 , 9 , 47 , 12 ) ;
347
364
VerifyConvert ( time1utc , s_strPacific , time1 . AddHours ( - 8 ) ) ;
348
- VerifyConvert ( time1utc , s_strSydney , time1 . AddHours ( 10 ) ) ;
365
+ VerifyConvert ( time1utc , s_strSydney , time1 . AddHours ( s_sydneyOffsetLastWeekOfMarch2006 ) ) ;
349
366
time1utc = new DateTime ( 2006 , 11 , 5 , 1 , 3 , 0 , DateTimeKind . Utc ) ;
350
367
time1 = new DateTime ( 2006 , 11 , 5 , 1 , 3 , 0 ) ;
351
368
VerifyConvert ( time1utc , s_strPacific , time1 . AddHours ( - 8 ) ) ;
@@ -382,8 +399,8 @@ public static void DateTimeVariousSystemTimeZonesTest()
382
399
VerifyConvert ( time1 , s_strPacific , s_strSydney , time1 . AddHours ( 17 ) ) ;
383
400
VerifyConvert ( time1 , s_strSydney , s_strPacific , time1 . AddHours ( - 17 ) ) ;
384
401
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 ) ) ) ;
387
404
time1 = new DateTime ( 2006 , 11 , 5 , 1 , 3 , 0 ) ;
388
405
VerifyConvert ( time1 , s_strPacific , s_strSydney , time1 . AddHours ( 19 ) ) ;
389
406
VerifyConvert ( time1 , s_strSydney , s_strPacific , time1 . AddHours ( - 19 ) ) ;
@@ -393,7 +410,6 @@ public static void DateTimeVariousSystemTimeZonesTest()
393
410
}
394
411
395
412
[ Fact ]
396
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
397
413
public static void PerthRulesTest ( )
398
414
{
399
415
var time1utc = new DateTime ( 2005 , 12 , 31 , 15 , 59 , 59 , DateTimeKind . Utc ) ;
@@ -424,11 +440,20 @@ public static void PerthRulesTest()
424
440
time1utc = new DateTime ( 2006 , 11 , 30 , 18 , 0 , 0 , DateTimeKind . Utc ) ;
425
441
time1 = new DateTime ( 2006 , 12 , 1 , 2 , 0 , 0 ) ;
426
442
VerifyConvert ( time1utc , s_strPerth , time1 ) ;
427
- // ambiguous time between rules
428
- // this is not ideal, but the way it works
443
+
429
444
time1utc = new DateTime ( 2006 , 12 , 31 , 15 , 59 , 59 , DateTimeKind . Utc ) ;
430
445
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
431
450
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
+ }
432
457
433
458
// 2007 rule
434
459
time1utc = new DateTime ( 2006 , 12 , 31 , 20 , 1 , 2 , DateTimeKind . Utc ) ;
@@ -512,7 +537,6 @@ public static void UtcToLocalTest()
512
537
}
513
538
514
539
[ Fact ]
515
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
516
540
public static void LocalToSystemTest ( )
517
541
{
518
542
var time1 = new DateTime ( 2006 , 5 , 12 , 5 , 17 , 42 ) ;
@@ -522,13 +546,16 @@ public static void LocalToSystemTest()
522
546
VerifyConvert ( time1local , s_strSydney , time1 . Subtract ( localOffset ) . AddHours ( 10 ) ) ;
523
547
VerifyConvert ( time1 , s_strPacific , time1 . Subtract ( localOffset ) . AddHours ( - 7 ) ) ;
524
548
VerifyConvert ( time1local , s_strPacific , time1 . Subtract ( localOffset ) . AddHours ( - 7 ) ) ;
549
+
525
550
time1 = new DateTime ( 2006 , 3 , 28 , 9 , 47 , 12 ) ;
526
551
time1local = new DateTime ( 2006 , 3 , 28 , 9 , 47 , 12 , DateTimeKind . Local ) ;
527
552
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
+
530
556
VerifyConvert ( time1 , s_strPacific , time1 . Subtract ( localOffset ) . AddHours ( - 8 ) ) ;
531
557
VerifyConvert ( time1local , s_strPacific , time1 . Subtract ( localOffset ) . AddHours ( - 8 ) ) ;
558
+
532
559
time1 = new DateTime ( 2006 , 11 , 5 , 1 , 3 , 0 ) ;
533
560
time1local = new DateTime ( 2006 , 11 , 5 , 1 , 3 , 0 , DateTimeKind . Local ) ;
534
561
localOffset = TimeZoneInfo . Local . GetUtcOffset ( time1 ) ;
@@ -603,7 +630,6 @@ public static void LocalToSystemTest()
603
630
}
604
631
605
632
[ Fact ]
606
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
607
633
public static void LocalToLocalTest ( )
608
634
{
609
635
if ( s_localIsPST )
@@ -662,7 +688,6 @@ public static void LocalToLocalTest()
662
688
}
663
689
664
690
[ Fact ]
665
- [ ActiveIssue ( 846 , PlatformID . AnyUnix ) ]
666
691
public static void LocalToUtcTest ( )
667
692
{
668
693
var time1 = new DateTime ( 1964 , 6 , 19 , 12 , 45 , 10 ) ;
0 commit comments