Skip to content

Commit

Permalink
Merge pull request #172 from ONLYOFFICE/bugfix/fixed-timezone-exception
Browse files Browse the repository at this point in the history
Bugfix/fixed timezone exception
  • Loading branch information
pavelbannov authored Jan 25, 2024
2 parents fa6042e + 80b3a9f commit 4a89565
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public string GetTimeZoneDisplayName(TimeZoneInfo tz)
return displayName;
}

public string GetIanaTimeZoneId(TimeZoneInfo timeZone)
{
if (timeZone.HasIanaId)
{
return timeZone.Id;
}

return TimeZoneInfo.TryConvertWindowsIdToIanaId(timeZone.Id, out var ianaTimeZoneId)
? ianaTimeZoneId
: WindowsTzId2OlsonTzId(timeZone.Id);
}

public string OlsonTzId2WindowsTzId(string olsonTimeZoneId, bool defaultIfNoMatch = true)
{
var mapZone = GetMapZoneByWindowsTzId(olsonTimeZoneId);
Expand Down
8 changes: 4 additions & 4 deletions web/ASC.Web.Api/Api/Settings/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public async Task<SettingsDto> GetSettingsAsync(bool? withpassword)
{
settings.TrustedDomains = tenant.TrustedDomains;
settings.TrustedDomainsType = tenant.TrustedDomainsType;
var timeZone = tenant.TimeZone;
settings.Timezone = _timeZoneConverter.WindowsTzId2OlsonTzId(timeZone);
settings.UtcOffset = _timeZoneConverter.GetTimeZone(timeZone).GetUtcOffset(DateTime.UtcNow);
var timeZone = _timeZoneConverter.GetTimeZone(tenant.TimeZone);
settings.Timezone = _timeZoneConverter.GetIanaTimeZoneId(timeZone);
settings.UtcOffset = timeZone.GetUtcOffset(DateTime.UtcNow);
settings.UtcHoursOffset = settings.UtcOffset.TotalHours;
settings.OwnerId = tenant.OwnerId;
settings.NameSchemaId = _customNamingPeople.Current.Id;
Expand Down Expand Up @@ -407,7 +407,7 @@ public async Task<List<TimezonesRequestsDto>> GetTimeZonesAsyncAsync()
{
listOfTimezones.Add(new TimezonesRequestsDto
{
Id = _timeZoneConverter.WindowsTzId2OlsonTzId(tz.Id),
Id = _timeZoneConverter.GetIanaTimeZoneId(tz),
DisplayName = _timeZoneConverter.GetTimeZoneDisplayName(tz)
});
}
Expand Down

0 comments on commit 4a89565

Please sign in to comment.