Browse Source

Enhance timezone handling to support both IANA and Windows timezones.

pull/22800/head
maliming 9 months ago
parent
commit
ecf7339397
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 27
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs

27
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs

@ -313,17 +313,40 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
{
var timeZone = await _settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone);
string? timeZoneId = null;
string? timeZoneName = null;
if (!timeZone.IsNullOrWhiteSpace())
{
try
{
if (_timezoneProvider.GetIanaTimezones().Any(x => x.Value == timeZone))
{
timeZoneId = _timezoneProvider.IanaToWindows(timeZone);
timeZoneName = timeZone;
}
else if (_timezoneProvider.GetWindowsTimezones().Any(x => x.Value == timeZone))
{
timeZoneId = timeZone;
timeZoneName = _timezoneProvider.WindowsToIana(timeZone);
}
}
catch (Exception ex)
{
Logger.LogWarning(ex, $"Exception occurred while getting timezone({timeZone}) information");
}
}
return new TimingDto
{
TimeZone = new TimeZone
{
Windows = new WindowsTimeZone
{
TimeZoneId = timeZone.IsNullOrWhiteSpace() ? null : _timezoneProvider.IanaToWindows(timeZone)
TimeZoneId = timeZoneId
},
Iana = new IanaTimeZone
{
TimeZoneName = timeZone
TimeZoneName = timeZoneName
}
}
};

Loading…
Cancel
Save