Skip to content

Commit e0415a2

Browse files
Merge pull request #90 from mj1856/obsolete-zones
Exclude obsolete zones from known IANA and Windows lists
2 parents 3e9d036 + 90f88ba commit e0415a2

File tree

4 files changed

+63
-17
lines changed

4 files changed

+63
-17
lines changed

src/TimeZoneConverter/TZConvert.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ static TZConvert()
4040
// Special case - not in any map.
4141
KnownIanaTimeZoneNames.Add("Antarctica/Troll");
4242

43+
// Remove zones from KnownIanaTimeZoneNames that have been removed from IANA data.
44+
// (They should still map to Windows zones correctly.)
45+
KnownIanaTimeZoneNames.Remove("Canada/East-Saskatchewan"); // Removed in 2017c
46+
KnownIanaTimeZoneNames.Remove("US/Pacific-New"); // Removed in 2018a
47+
48+
// Remove zones from KnownWindowsTimeZoneIds that are marked obsolete in the Windows Registry.
49+
// (They should still map to IANA zones correctly.)
50+
KnownWindowsTimeZoneIds.Remove("Kamchatka Standard Time");
51+
KnownWindowsTimeZoneIds.Remove("Mid-Atlantic Standard Time");
52+
4353
#if !NETSTANDARD1_1
4454
SystemTimeZones = GetSystemTimeZones();
4555
#endif
@@ -325,23 +335,7 @@ private static Dictionary<string, TimeZoneInfo> GetSystemTimeZones()
325335
if (IsWindows)
326336
return TimeZoneInfo.GetSystemTimeZones().ToDictionary(x => x.Id, x => x, StringComparer.OrdinalIgnoreCase);
327337

328-
var zones = GetSystemTimeZonesLinux().ToDictionary(x => x.Id, x => x, StringComparer.OrdinalIgnoreCase);
329-
330-
// Include special case to resolve deleted link
331-
if (!zones.ContainsKey("Canada/East-Saskatchewan"))
332-
{
333-
try
334-
{
335-
var tzi = TimeZoneInfo.FindSystemTimeZoneById("Canada/Saskatchewan");
336-
zones.Add("Canada/East-Saskatchewan", tzi);
337-
}
338-
catch
339-
{
340-
// ignored
341-
}
342-
}
343-
344-
return zones;
338+
return GetSystemTimeZonesLinux().ToDictionary(x => x.Id, x => x, StringComparer.OrdinalIgnoreCase);
345339
#else
346340
return TimeZoneInfo.GetSystemTimeZones().ToDictionary(x => x.Id, x => x, StringComparer.OrdinalIgnoreCase);
347341
#endif

test/TimeZoneConverter.Tests/IanaToWindowsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,19 @@ public void Can_Convert_Europe_Skopje_To_Windows()
102102
string result = TZConvert.IanaToWindows("Europe/Skopje");
103103
Assert.Equal("Central European Standard Time", result);
104104
}
105+
106+
[Fact]
107+
public void Can_Convert_East_Saskatchewan_To_Windows()
108+
{
109+
string result = TZConvert.IanaToWindows("Canada/East-Saskatchewan");
110+
Assert.Equal("Canada Central Standard Time", result);
111+
}
112+
113+
[Fact]
114+
public void Can_Convert_Pacific_New_To_Windows()
115+
{
116+
string result = TZConvert.IanaToWindows("US/Pacific-New");
117+
Assert.Equal("Pacific Standard Time", result);
118+
}
105119
}
106120
}

test/TimeZoneConverter.Tests/KnownTimeZonesTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,29 @@ public void Known_IANA_TimeZones_Includes_Unmappable_Zones()
2727
{
2828
Assert.Contains(TZConvert.KnownIanaTimeZoneNames, x => x == "Antarctica/Troll");
2929
}
30+
31+
[Fact]
32+
public void Known_IANA_TimeZones_Excludes_East_Saskatchewan()
33+
{
34+
Assert.DoesNotContain(TZConvert.KnownIanaTimeZoneNames, x => x == "Canada/East-Saskatchewan");
35+
}
36+
37+
[Fact]
38+
public void Known_IANA_TimeZones_Excludes_Pacific_New()
39+
{
40+
Assert.DoesNotContain(TZConvert.KnownIanaTimeZoneNames, x => x == "US/Pacific-New");
41+
}
42+
43+
[Fact]
44+
public void Known_Windows_TimeZones_Excludes_Kamchatka()
45+
{
46+
Assert.DoesNotContain(TZConvert.KnownWindowsTimeZoneIds, x => x == "Kamchatka Standard Time");
47+
}
48+
49+
[Fact]
50+
public void Known_Windows_TimeZones_Excludes_Mid_Atlantic()
51+
{
52+
Assert.DoesNotContain(TZConvert.KnownWindowsTimeZoneIds, x => x == "Mid-Atlantic Standard Time");
53+
}
3054
}
3155
}

test/TimeZoneConverter.Tests/WindowsToIanaTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,19 @@ public void Can_Convert_Yukon_Standard_Time_To_IANA()
107107
string result = TZConvert.WindowsToIana("Yukon Standard Time");
108108
Assert.Equal("America/Whitehorse", result);
109109
}
110+
111+
[Fact]
112+
public void Can_Convert_Kamchatka_Standard_Time_To_IANA()
113+
{
114+
string result = TZConvert.WindowsToIana("Kamchatka Standard Time");
115+
Assert.Equal("Asia/Kamchatka", result);
116+
}
117+
118+
[Fact]
119+
public void Can_Convert_Mid_Atlantic_Standard_Time_To_IANA()
120+
{
121+
string result = TZConvert.WindowsToIana("Mid-Atlantic Standard Time");
122+
Assert.Equal("Etc/GMT+2", result);
123+
}
110124
}
111125
}

0 commit comments

Comments
 (0)