From 8adc61b28784b5a4f4fb0934b955b9e19c03e5da Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 2 Apr 2025 10:59:48 +0800 Subject: [PATCH] Add browser timezone retrieval and update timezone handling logic --- .../wwwroot/libs/abp/js/abp.js | 3 +++ ...bAssemblyCachedApplicationConfigurationClient.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js b/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js index 52bec9bb7b..30f1915005 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js @@ -252,4 +252,7 @@ var abp = abp || {}; abp.utils.setCookieValue('__timezone', Intl.DateTimeFormat().resolvedOptions().timeZone, new Date(new Date().setFullYear(new Date().getFullYear() + 1)), '/'); } + abp.clock.getBrowserTimeZone = function () { + return Intl.DateTimeFormat().resolvedOptions().timeZone + } })(); diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs index e1256eb53e..aa80a5c3b0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Microsoft.JSInterop; using Volo.Abp.AspNetCore.Components.Web.Security; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; @@ -79,11 +80,13 @@ public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicatio configurationDto.CurrentTenant.Name ); - CurrentTimezoneProvider.TimeZone = configurationDto.Timing.TimeZone.Iana.TimeZoneName; - - if (Clock.SupportsMultipleTimezone && !configurationDto.CurrentUser.IsAuthenticated) + if (Clock.SupportsMultipleTimezone) { - await JSRuntime.InvokeVoidAsync("abp.clock.setBrowserTimeZoneToCookie"); + CurrentTimezoneProvider.TimeZone = !configurationDto.Timing.TimeZone.Iana.TimeZoneName.IsNullOrWhiteSpace() + ? configurationDto.Timing.TimeZone.Iana.TimeZoneName + : await JSRuntime.InvokeAsync("abp.clock.getBrowserTimeZone"); + + await JSRuntime.InvokeAsync("abp.clock.setBrowserTimeZoneToCookie"); } }