Browse Source

Refactor timezone retrieval logic to prioritize settings, request, and server fallback

pull/22236/head
maliming 1 year ago
parent
commit
98fbeaf656
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 14
      framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Timing/AbpTimeZoneMiddleware.cs

14
framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Timing/AbpTimeZoneMiddleware.cs

@ -21,21 +21,19 @@ public class AbpTimeZoneMiddleware : AbpMiddlewareBase, ITransientDependency
return;
}
string? timezone = null;
if (!context.RequestServices.GetRequiredService<ICurrentUser>().IsAuthenticated)
{
timezone = await GetTimezoneFromRequestAsync(context);
}
// Try to get the timezone from the setting system first
var settingProvider = context.RequestServices.GetRequiredService<ISettingProvider>();
var timezone = await settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone);
if (timezone.IsNullOrWhiteSpace())
{
var settingProvider = context.RequestServices.GetRequiredService<ISettingProvider>();
timezone = await settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone);
// Try to get the timezone from the HTTP request if the setting is not available
timezone = await GetTimezoneFromRequestAsync(context);
}
if (timezone.IsNullOrWhiteSpace())
{
// Try to get the timezone from the current running server if the setting and request are not available
timezone = context.RequestServices.GetRequiredService<ITimezoneProvider>().GetCurrentIanaTimezoneName();
}

Loading…
Cancel
Save