From 85085bf4c7c29f8f32b6ae8959f4f36fe99c689f Mon Sep 17 00:00:00 2001 From: sbwalker Date: Thu, 5 Jun 2025 10:37:25 -0400 Subject: [PATCH] stop gap fix to mitigate date conversion exceptions on WebAssembly --- Oqtane.Client/Modules/ModuleBase.cs | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs index 39681067..0dabafd3 100644 --- a/Oqtane.Client/Modules/ModuleBase.cs +++ b/Oqtane.Client/Modules/ModuleBase.cs @@ -500,17 +500,24 @@ namespace Oqtane.Modules }; } - // date methods + // date conversion methods public DateTime? UtcToLocal(DateTime? datetime) { TimeZoneInfo timezone = null; - if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + try { - timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + } + else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + } } - else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + catch { - timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + // The time zone ID was not found on the local computer } return Utilities.UtcAsLocalDateTime(datetime, timezone); } @@ -518,13 +525,20 @@ namespace Oqtane.Modules public DateTime? LocalToUtc(DateTime? datetime) { TimeZoneInfo timezone = null; - if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + try { - timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + } + else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + } } - else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + catch { - timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + // The time zone ID was not found on the local computer } return Utilities.LocalDateAndTimeAsUtc(datetime, timezone); }