hopefully fix timezoneinfo on dotnet core 3.0

This commit is contained in:
13xforever 2019-11-06 05:27:20 +05:00
parent 8c50ecddaa
commit e86e6a89ff

View File

@ -10,14 +10,14 @@ namespace CompatBot.Utils
public static readonly Dictionary<string, string[]> TimeZoneAcronyms = new Dictionary<string, string[]> public static readonly Dictionary<string, string[]> TimeZoneAcronyms = new Dictionary<string, string[]>
{ {
["PT"] = new[] { "Pacific Standard Time" }, ["PT"] = new[] { "Pacific Standard Time", "America/Los_Angeles" },
["PST"] = new[] { "Pacific Standard Time" }, ["PST"] = new[] { "Pacific Standard Time", "America/Los_Angeles" },
["PDT"] = new[] { "Pacific Standard Time" }, ["PDT"] = new[] { "Pacific Standard Time", "Pacific Daylight Time", "America/Los_Angeles" },
["EST"] = new[] { "Eastern Standard Time" }, ["EST"] = new[] { "Eastern Standard Time", "America/New_York" },
["EDT"] = new[] { "Eastern Standard Time" }, ["EDT"] = new[] { "Eastern Standard Time", "Eastern Daylight Time", "America/New_York" },
["CEST"] = new[] { "Central European Standard Time" }, ["CEST"] = new[] { "Central European Standard Time", "Europe/Berlin" },
["BST"] = new[] { "British Summer Time", "GMT Standard Time" }, ["BST"] = new[] { "British Summer Time", "GMT Standard Time", "Europe/London" },
["JST"] = new[] { "Japan Standard Time", "Tokyo Standard Time" }, ["JST"] = new[] { "Japan Standard Time", "Tokyo Standard Time", "Asia/Tokyo" },
}; };
static TimeParser() static TimeParser()
@ -28,25 +28,25 @@ namespace CompatBot.Utils
select tzn, select tzn,
StringComparer.InvariantCultureIgnoreCase StringComparer.InvariantCultureIgnoreCase
); );
Config.Log.Debug("[TZI] Unique TZA names: " + uniqueNames.Count); Config.Log.Trace("[TZI] Unique TZA names: " + uniqueNames.Count);
var tzList = TimeZoneInfo.GetSystemTimeZones(); var tzList = TimeZoneInfo.GetSystemTimeZones();
Config.Log.Debug("[TZI] System TZI count: " + tzList.Count); Config.Log.Trace("[TZI] System TZI count: " + tzList.Count);
var result = new Dictionary<string, TimeZoneInfo>(); var result = new Dictionary<string, TimeZoneInfo>();
foreach (var tzi in tzList) foreach (var tzi in tzList)
{ {
Config.Log.Debug($"[TZI] Checking {tzi.Id} ({tzi.DisplayName} / {tzi.StandardName} / {tzi.DaylightName})"); Config.Log.Trace($"[TZI] Checking {tzi.Id} ({tzi.DisplayName} / {tzi.StandardName} / {tzi.DaylightName})");
if (uniqueNames.Contains(tzi.StandardName) || uniqueNames.Contains(tzi.DaylightName) || uniqueNames.Contains(tzi.DisplayName)) if (uniqueNames.Contains(tzi.StandardName) || uniqueNames.Contains(tzi.DaylightName) || uniqueNames.Contains(tzi.Id))
{ {
Config.Log.Debug("[TZI] Looks like it's a match!"); Config.Log.Trace("[TZI] Looks like it's a match!");
var acronyms = from tza in TimeZoneAcronyms var acronyms = from tza in TimeZoneAcronyms
where tza.Value.Contains(tzi.StandardName) || tza.Value.Contains(tzi.DaylightName) || tza.Value.Contains(tzi.DisplayName) where tza.Value.Contains(tzi.StandardName) || tza.Value.Contains(tzi.DaylightName) || tza.Value.Contains(tzi.Id)
select tza.Key; select tza.Key;
Config.Log.Debug("[TZI] Matched acronyms: " + string.Join(", ", acronyms)); Config.Log.Trace("[TZI] Matched acronyms: " + string.Join(", ", acronyms));
foreach (var tza in acronyms) foreach (var tza in acronyms)
result[tza] = tzi; result[tza] = tzi;
} }
} }
Config.Log.Debug("[TZI] Total matched acronyms: " + result.Count); Config.Log.Trace("[TZI] Total matched acronyms: " + result.Count);
TimeZoneMap = result; TimeZoneMap = result;
} }