Skip to content

Commit c7b9b84

Browse files
authored
Merge pull request #22800 from abpframework/GetTimingConfig
Enhance timezone handling to support both IANA and Windows timezones.
2 parents d78754b + 9c5c737 commit c7b9b84

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,42 @@ protected virtual async Task<TimingDto> GetTimingConfigAsync()
313313
{
314314
var timeZone = await _settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone);
315315

316+
string? timeZoneId = null;
317+
string? timeZoneName = null;
318+
if (!timeZone.IsNullOrWhiteSpace())
319+
{
320+
try
321+
{
322+
if (_timezoneProvider.GetIanaTimezones().Any(x => x.Value == timeZone))
323+
{
324+
timeZoneId = _timezoneProvider.IanaToWindows(timeZone);
325+
timeZoneName = timeZone;
326+
}
327+
else if (_timezoneProvider.GetWindowsTimezones().Any(x => x.Value == timeZone))
328+
{
329+
timeZoneId = timeZone;
330+
timeZoneName = _timezoneProvider.WindowsToIana(timeZone);
331+
}
332+
}
333+
catch (Exception ex)
334+
{
335+
timeZoneId = null;
336+
timeZoneName = null;
337+
Logger.LogWarning(ex, $"Exception occurred while getting timezone({timeZone}) information");
338+
}
339+
}
340+
316341
return new TimingDto
317342
{
318343
TimeZone = new TimeZone
319344
{
320345
Windows = new WindowsTimeZone
321346
{
322-
TimeZoneId = timeZone.IsNullOrWhiteSpace() ? null : _timezoneProvider.IanaToWindows(timeZone)
347+
TimeZoneId = timeZoneId
323348
},
324349
Iana = new IanaTimeZone
325350
{
326-
TimeZoneName = timeZone
351+
TimeZoneName = timeZoneName
327352
}
328353
}
329354
};

0 commit comments

Comments
 (0)