From 4f67b1174fe2d252a6417c85b5c53f3c2da3dc26 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 21 Jan 2023 19:12:53 -0800 Subject: [PATCH] fix: Some computers are missing timezones apparently (#1322) Some windows servers are not updated properly. Specifically Windows 10/2016 and older that is missing the September 2020 rollup will throw an error: See [here](https://support.microsoft.com/en-us/topic/dst-changes-in-windows-for-yukon-canada-september-8-2020-ae74d7b8-82ed-1d35-e131-fb0796b73b10) for information about this update and how to get it. --- Projects/Server/TimeZones/TimeZoneHandler.cs | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Projects/Server/TimeZones/TimeZoneHandler.cs b/Projects/Server/TimeZones/TimeZoneHandler.cs index da3b2f984..5c3bb80bf 100644 --- a/Projects/Server/TimeZones/TimeZoneHandler.cs +++ b/Projects/Server/TimeZones/TimeZoneHandler.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using Server.Json; +using Server.Logging; namespace Server; @@ -39,6 +40,8 @@ namespace Server; */ public static class TimeZoneHandler { + private static readonly ILogger logger = LogFactory.GetLogger(typeof(TimeZoneHandler)); + private static readonly Dictionary _timeZoneById = new(); public static TimeZoneInfo SystemTimeZone { get; private set; } @@ -47,17 +50,24 @@ public static class TimeZoneHandler var timezones = JsonConfig.Deserialize(Path.Combine(Core.BaseDirectory, "Data/timezones.json")); foreach (var tz in timezones) { - // Get the timezone if we are on Windows - var tzInfo = Core.IsWindows ? TimeZoneInfo.FindSystemTimeZoneById(tz.TimeZone) : null; - - foreach (var region in tz.Regions) + try { - // Get the timezone by region if we are on linux - tzInfo ??= TimeZoneInfo.FindSystemTimeZoneById(region); - _timeZoneById[region] = tzInfo; - } + // Get the timezone if we are on Windows + var tzInfo = Core.IsWindows ? TimeZoneInfo.FindSystemTimeZoneById(tz.TimeZone) : null; - _timeZoneById[tz.TimeZone] = tzInfo; + foreach (var region in tz.Regions) + { + // Get the timezone by region if we are on linux + tzInfo ??= TimeZoneInfo.FindSystemTimeZoneById(region); + _timeZoneById[region] = tzInfo; + } + + _timeZoneById[tz.TimeZone] = tzInfo; + } + catch (TimeZoneNotFoundException e) + { + logger.Warning(e, $"Timezone '{tz.TimeZone}' was not found."); + } } }