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

Commit fe9f9c5

Browse files
committed
Merge pull request #2728 from eerhardt/master
Adding a test case for TimeZoneInfo.GetSystemTimeZones.
2 parents f3c4f89 + 381c91e commit fe9f9c5

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

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

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

44
using System;
5+
using System.Collections.ObjectModel;
56
using System.Globalization;
67
using System.Runtime.InteropServices;
78
using Xunit;
@@ -20,7 +21,7 @@ public static class TimeZoneInfoTests
2021
private static String s_strAmsterdam = s_isWindows ? "W. Europe Standard Time" : "Europe/Berlin";
2122
private static String s_strRussian = s_isWindows ? "Russian Standard Time" : "Europe/Moscow";
2223
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";
2425
private static String s_strLisbon = s_isWindows ? "GMT Standard Time" : "Europe/Lisbon";
2526
private static String s_strNewfoundland = s_isWindows ? "Newfoundland Standard Time" : "America/St_Johns";
2627

@@ -1712,14 +1713,14 @@ public static void TestLisbonDaylightSavingsWithNoOffsetChange(string dateTimeSt
17121713

17131714
[Theory]
17141715
// 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
17161717
[InlineData("2015-03-08T01:59:59", false, false, false, "-3:30:00", "-8:00:00")]
17171718
// 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")]
17231724
[InlineData("2015-11-01T00:59:59", true, false, false, "-2:30:00", "-7:00:00")]
17241725
[InlineData("2015-11-01T01:00:00", false, false, true, "-3:30:00", "-7:00:00")]
17251726
[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
17451746
}
17461747
}
17471748

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+
17481788
//
17491789
// Helper Methods
17501790
//

0 commit comments

Comments
 (0)