Browse Source

Add browser timezone retrieval and update timezone handling logic

pull/22236/head
maliming 2 years ago
parent
commit
8adc61b287
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 3
      framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js
  2. 13
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs

3
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.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
}
})(); })();

13
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 Microsoft.JSInterop;
using Volo.Abp.AspNetCore.Components.Web.Security; using Volo.Abp.AspNetCore.Components.Web.Security;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
@ -79,11 +80,13 @@ public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicatio
configurationDto.CurrentTenant.Name configurationDto.CurrentTenant.Name
); );
CurrentTimezoneProvider.TimeZone = configurationDto.Timing.TimeZone.Iana.TimeZoneName; if (Clock.SupportsMultipleTimezone)
if (Clock.SupportsMultipleTimezone && !configurationDto.CurrentUser.IsAuthenticated)
{ {
await JSRuntime.InvokeVoidAsync("abp.clock.setBrowserTimeZoneToCookie"); CurrentTimezoneProvider.TimeZone = !configurationDto.Timing.TimeZone.Iana.TimeZoneName.IsNullOrWhiteSpace()
? configurationDto.Timing.TimeZone.Iana.TimeZoneName
: await JSRuntime.InvokeAsync<string>("abp.clock.getBrowserTimeZone");
await JSRuntime.InvokeAsync<string>("abp.clock.setBrowserTimeZoneToCookie");
} }
} }

Loading…
Cancel
Save