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 . Collections . ObjectModel ;
5
6
using System . Globalization ;
6
7
using System . Runtime . InteropServices ;
7
8
using Xunit ;
@@ -20,7 +21,7 @@ public static class TimeZoneInfoTests
20
21
private static String s_strAmsterdam = s_isWindows ? "W. Europe Standard Time" : "Europe/Berlin" ;
21
22
private static String s_strRussian = s_isWindows ? "Russian Standard Time" : "Europe/Moscow" ;
22
23
private static String s_strLibya = s_isWindows ? "Libya Standard Time" : "Africa/Tripoli" ;
23
- private static String s_strCatamarca = s_isWindows ? "Argentina Standard Time" : "America/Catamarca" ;
24
+ private static String s_strCatamarca = s_isWindows ? "Argentina Standard Time" : "America/Argentina/ Catamarca" ;
24
25
private static String s_strLisbon = s_isWindows ? "GMT Standard Time" : "Europe/Lisbon" ;
25
26
private static String s_strNewfoundland = s_isWindows ? "Newfoundland Standard Time" : "America/St_Johns" ;
26
27
@@ -1712,14 +1713,14 @@ public static void TestLisbonDaylightSavingsWithNoOffsetChange(string dateTimeSt
1712
1713
1713
1714
[ Theory ]
1714
1715
// Newfoundland is UTC-3:30 standard and UTC-2:30 dst
1715
- // using non-UTC date times in this test to get some converage for non-UTC date times
1716
+ // using non-UTC date times in this test to get some coverage for non-UTC date times
1716
1717
[ InlineData ( "2015-03-08T01:59:59" , false , false , false , "-3:30:00" , "-8:00:00" ) ]
1717
1718
// since DST kicks in a 2AM, from 2AM - 3AM is Invalid
1718
- [ InlineData ( "2015-03-08T02:00:00" , false , true , false , "-3:30:00" , "-8:00:00" ) ]
1719
- [ InlineData ( "2015-03-08T02:59:59" , false , true , false , "-3:30:00" , "-8:00:00" ) ]
1720
- [ InlineData ( "2015-03-08T03:00:00" , true , false , false , "-2:30:00" , "-8:00:00" ) ]
1721
- [ InlineData ( "2015-03-08T07:29:59" , true , false , false , "-2:30:00" , "-8:00:00" ) ]
1722
- [ InlineData ( "2015-03-08T07:30:00" , true , false , false , "-2:30:00" , "-7:00:00" ) ]
1719
+ [ InlineData ( "2015-03-08T02:00:00" , false , true , false , "-3:30:00" , "-8:00:00" ) ]
1720
+ [ InlineData ( "2015-03-08T02:59:59" , false , true , false , "-3:30:00" , "-8:00:00" ) ]
1721
+ [ InlineData ( "2015-03-08T03:00:00" , true , false , false , "-2:30:00" , "-8:00:00" ) ]
1722
+ [ InlineData ( "2015-03-08T07:29:59" , true , false , false , "-2:30:00" , "-8:00:00" ) ]
1723
+ [ InlineData ( "2015-03-08T07:30:00" , true , false , false , "-2:30:00" , "-7:00:00" ) ]
1723
1724
[ InlineData ( "2015-11-01T00:59:59" , true , false , false , "-2:30:00" , "-7:00:00" ) ]
1724
1725
[ InlineData ( "2015-11-01T01:00:00" , false , false , true , "-3:30:00" , "-7:00:00" ) ]
1725
1726
[ InlineData ( "2015-11-01T01:59:59" , false , false , true , "-3:30:00" , "-7:00:00" ) ]
@@ -1745,6 +1746,45 @@ public static void TestNewfoundlandTimeZone(string dateTimeString, bool expected
1745
1746
}
1746
1747
}
1747
1748
1749
+ [ Fact ]
1750
+ public static void TestGetSystemTimeZones ( )
1751
+ {
1752
+ ReadOnlyCollection < TimeZoneInfo > timeZones = TimeZoneInfo . GetSystemTimeZones ( ) ;
1753
+ Assert . NotEmpty ( timeZones ) ;
1754
+ Assert . Contains ( timeZones , t => t . Id == s_strPacific ) ;
1755
+ Assert . Contains ( timeZones , t => t . Id == s_strSydney ) ;
1756
+ Assert . Contains ( timeZones , t => t . Id == s_strGMT ) ;
1757
+ Assert . Contains ( timeZones , t => t . Id == s_strTonga ) ;
1758
+ Assert . Contains ( timeZones , t => t . Id == s_strBrasil ) ;
1759
+ Assert . Contains ( timeZones , t => t . Id == s_strPerth ) ;
1760
+ Assert . Contains ( timeZones , t => t . Id == s_strBrasilia ) ;
1761
+ Assert . Contains ( timeZones , t => t . Id == s_strNairobi ) ;
1762
+ Assert . Contains ( timeZones , t => t . Id == s_strAmsterdam ) ;
1763
+ Assert . Contains ( timeZones , t => t . Id == s_strRussian ) ;
1764
+ Assert . Contains ( timeZones , t => t . Id == s_strLibya ) ;
1765
+ Assert . Contains ( timeZones , t => t . Id == s_strCatamarca ) ;
1766
+ Assert . Contains ( timeZones , t => t . Id == s_strLisbon ) ;
1767
+ Assert . Contains ( timeZones , t => t . Id == s_strNewfoundland ) ;
1768
+
1769
+ // ensure the TimeZoneInfos are sorted by BaseUtcOffset and then DisplayName.
1770
+ TimeZoneInfo previous = timeZones [ 0 ] ;
1771
+ for ( int i = 1 ; i < timeZones . Count ; i ++ )
1772
+ {
1773
+ TimeZoneInfo current = timeZones [ i ] ;
1774
+ int baseOffsetsCompared = current . BaseUtcOffset . CompareTo ( previous . BaseUtcOffset ) ;
1775
+ Assert . True ( baseOffsetsCompared >= 0 ,
1776
+ string . Format ( "TimeZoneInfos are out of order. {0}:{1} should be before {2}:{3}" ,
1777
+ previous . Id , previous . BaseUtcOffset , current . Id , current . BaseUtcOffset ) ) ;
1778
+
1779
+ if ( baseOffsetsCompared == 0 )
1780
+ {
1781
+ Assert . True ( current . DisplayName . CompareTo ( previous . DisplayName ) >= 0 ,
1782
+ string . Format ( "TimeZoneInfos are out of order. {0} should be before {1}" ,
1783
+ previous . DisplayName , current . DisplayName ) ) ;
1784
+ }
1785
+ }
1786
+ }
1787
+
1748
1788
//
1749
1789
// Helper Methods
1750
1790
//
0 commit comments