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

Commit dbbe11d

Browse files
author
Eric Erhardt
committed
Adding a TimeZoneInfo test for Newfoundland.
Newfoundland has an offset of UTC-3:30 and UTC-2:30, ensuring the TimeZoneInfo class handles this correctly.
1 parent 9406f90 commit dbbe11d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class TimeZoneInfoTests
2121
private static String s_strLibya = s_isWindows ? "Libya Standard Time" : "Africa/Tripoli";
2222
private static String s_strCatamarca = s_isWindows ? "Argentina Standard Time" : "America/Catamarca";
2323
private static String s_strLisbon = Interop.IsWindows ? "GMT Standard Time" : "Europe/Lisbon";
24+
private static String s_strNewfoundland = Interop.IsWindows ? "Newfoundland Standard Time" : "America/St_Johns";
2425

2526
private static TimeZoneInfo s_myUtc = TimeZoneInfo.Utc;
2627
private static TimeZoneInfo s_myLocal = TimeZoneInfo.Local;
@@ -30,6 +31,7 @@ public static class TimeZoneInfoTests
3031
private static TimeZoneInfo s_amsterdamTz = TimeZoneInfo.FindSystemTimeZoneById(s_strAmsterdam);
3132
private static TimeZoneInfo s_catamarcaTz = TimeZoneInfo.FindSystemTimeZoneById(s_strCatamarca);
3233
private static TimeZoneInfo s_LisbonTz = TimeZoneInfo.FindSystemTimeZoneById(s_strLisbon);
34+
private static TimeZoneInfo s_NewfoundlandTz = TimeZoneInfo.FindSystemTimeZoneById(s_strNewfoundland);
3335

3436
private static bool s_localIsPST = TimeZoneInfo.Local.Id == s_strPacific;
3537
private static bool s_regLocalSupportsDST = s_regLocal.SupportsDaylightSavingTime;
@@ -1707,6 +1709,41 @@ public static void TestLisbonDaylightSavingsWithNoOffsetChange(string dateTimeSt
17071709
Assert.Equal(offset, s_LisbonTz.GetUtcOffset(dt));
17081710
}
17091711

1712+
[Theory]
1713+
// Newfoundland is UTC-3:30 standard and UTC-2:30 dst
1714+
// using non-UTC date times in this test to get some converage for non-UTC date times
1715+
[InlineData("2015-03-08T01:59:59", false, false, false, "-3:30:00", "-8:00:00")]
1716+
// since DST kicks in a 2AM, from 2AM - 3AM is Invalid
1717+
[InlineData("2015-03-08T02:00:00", false, true, false,"-3:30:00", "-8:00:00")]
1718+
[InlineData("2015-03-08T02:59:59", false, true, false,"-3:30:00", "-8:00:00")]
1719+
[InlineData("2015-03-08T03:00:00", true, false, false,"-2:30:00", "-8:00:00")]
1720+
[InlineData("2015-03-08T07:29:59", true, false, false,"-2:30:00", "-8:00:00")]
1721+
[InlineData("2015-03-08T07:30:00", true, false, false,"-2:30:00", "-7:00:00")]
1722+
[InlineData("2015-11-01T00:59:59", true, false, false, "-2:30:00", "-7:00:00")]
1723+
[InlineData("2015-11-01T01:00:00", false, false, true, "-3:30:00", "-7:00:00")]
1724+
[InlineData("2015-11-01T01:59:59", false, false, true, "-3:30:00", "-7:00:00")]
1725+
[InlineData("2015-11-01T02:00:00", false, false, false, "-3:30:00", "-7:00:00")]
1726+
[InlineData("2015-11-01T05:29:59", false, false, false, "-3:30:00", "-7:00:00")]
1727+
[InlineData("2015-11-01T05:30:00", false, false, false, "-3:30:00", "-8:00:00")]
1728+
public static void TestNewfoundlandTimeZone(string dateTimeString, bool expectedDST, bool isInvalidTime, bool isAmbiguousTime,
1729+
string expectedOffsetString, string pacificOffsetString)
1730+
{
1731+
DateTime dt = DateTime.ParseExact(dateTimeString, "s", CultureInfo.InvariantCulture);
1732+
VerifyInv(s_NewfoundlandTz, dt, isInvalidTime);
1733+
1734+
if (!isInvalidTime)
1735+
{
1736+
VerifyDST(s_NewfoundlandTz, dt, expectedDST);
1737+
VerifyAmbiguous(s_NewfoundlandTz, dt, isAmbiguousTime);
1738+
1739+
TimeSpan offset = TimeSpan.Parse(expectedOffsetString, CultureInfo.InvariantCulture);
1740+
Assert.Equal(offset, s_NewfoundlandTz.GetUtcOffset(dt));
1741+
1742+
TimeSpan pacificOffset = TimeSpan.Parse(pacificOffsetString, CultureInfo.InvariantCulture);
1743+
VerifyConvert(dt, s_strNewfoundland, s_strPacific, dt - (offset - pacificOffset));
1744+
}
1745+
}
1746+
17101747
//
17111748
// Helper Methods
17121749
//
@@ -1817,4 +1854,10 @@ private static void VerifyInv(TimeZoneInfo tz, DateTime dt, bool expectedInvalid
18171854
bool ret = tz.IsInvalidTime(dt);
18181855
Assert.True(expectedInvalid == ret, String.Format("Test with the zone {0} and date {1} failed", tz.Id, dt));
18191856
}
1857+
1858+
private static void VerifyAmbiguous(TimeZoneInfo tz, DateTime dt, bool expectedAmbiguous)
1859+
{
1860+
bool ret = tz.IsAmbiguousTime(dt);
1861+
Assert.True(expectedAmbiguous == ret, String.Format("Test with the zone {0} and date {1} failed", tz.Id, dt));
1862+
}
18201863
}

0 commit comments

Comments
 (0)