stop gap fix to mitigate date conversion exceptions on WebAssembly

This commit is contained in:
sbwalker
2025-06-05 10:37:25 -04:00
parent 4418e27c29
commit 85085bf4c7

View File

@ -500,10 +500,12 @@ namespace Oqtane.Modules
}; };
} }
// date methods // date conversion methods
public DateTime? UtcToLocal(DateTime? datetime) public DateTime? UtcToLocal(DateTime? datetime)
{ {
TimeZoneInfo timezone = null; TimeZoneInfo timezone = null;
try
{
if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId))
{ {
timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId);
@ -512,12 +514,19 @@ namespace Oqtane.Modules
{ {
timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId);
} }
}
catch
{
// The time zone ID was not found on the local computer
}
return Utilities.UtcAsLocalDateTime(datetime, timezone); return Utilities.UtcAsLocalDateTime(datetime, timezone);
} }
public DateTime? LocalToUtc(DateTime? datetime) public DateTime? LocalToUtc(DateTime? datetime)
{ {
TimeZoneInfo timezone = null; TimeZoneInfo timezone = null;
try
{
if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId))
{ {
timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId);
@ -526,6 +535,11 @@ namespace Oqtane.Modules
{ {
timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId);
} }
}
catch
{
// The time zone ID was not found on the local computer
}
return Utilities.LocalDateAndTimeAsUtc(datetime, timezone); return Utilities.LocalDateAndTimeAsUtc(datetime, timezone);
} }