Settings: fix timeZones for unix

This commit is contained in:
pavelbannov 2020-09-03 18:30:14 +03:00
parent 5271c7f2f5
commit 82dd4a8828
2 changed files with 29 additions and 17 deletions

View File

@ -47,7 +47,8 @@ namespace ASC.Common.Utils
private IEnumerable<MapZone> _mapZones;
private bool _customMode;
private bool _customMode;
private bool _isMono;
private Dictionary<string, string> _translations;
@ -87,6 +88,26 @@ namespace ASC.Common.Utils
Log.Error(error);
}
}
public string GetTimeZoneDisplayName(TimeZoneInfo tz)
{
var displayName = GetTimeZoneName(tz);
if (!displayName.StartsWith("(UTC") && !displayName.StartsWith("UTC"))
{
if (tz.BaseUtcOffset != TimeSpan.Zero)
{
var offSet = tz.BaseUtcOffset < TimeSpan.Zero ? "-" : "+";
var name = tz.BaseUtcOffset.ToString(@"hh\:mm");
displayName = $"(UTC{offSet}{name}) {displayName}";
}
else
{
displayName = "(UTC) " + displayName;
}
}
return displayName;
}
public string OlsonTzId2WindowsTzId(string olsonTimeZoneId, bool defaultIfNoMatch = true)
{
@ -231,7 +252,7 @@ namespace ASC.Common.Utils
public string GetTimeZoneName(TimeZoneInfo timeZone)
{
if (!_customMode)
return timeZone.DisplayName;
return _isMono ? timeZone.Id : timeZone.DisplayName;
return _translations.ContainsKey(timeZone.Id) ? _translations[timeZone.Id] : timeZone.DisplayName;
}
@ -253,7 +274,8 @@ namespace ASC.Common.Utils
{
var id = string.Empty;
if (File.Exists("/etc/timezone"))
{
{
_isMono = true;
id = File.ReadAllText("/etc/timezone").Trim();
}

View File

@ -560,21 +560,11 @@ namespace ASC.Api.Settings
foreach (var tz in timeZones.OrderBy(z => z.BaseUtcOffset))
{
var displayName = tz.DisplayName;
if (!displayName.StartsWith("(UTC") && !displayName.StartsWith("UTC"))
listOfTimezones.Add(new TimezonesModel
{
if (tz.BaseUtcOffset != TimeSpan.Zero)
{
displayName = string.Format("(UTC{0}{1}) ", tz.BaseUtcOffset < TimeSpan.Zero ? "-" : "+", tz.BaseUtcOffset.ToString(@"hh\:mm")) + displayName;
}
else
{
displayName = "(UTC) " + displayName;
}
}
listOfTimezones.Add(new TimezonesModel { Id = tz.Id, DisplayName = displayName });
Id = tz.Id,
DisplayName = TimeZoneConverter.GetTimeZoneDisplayName(tz)
});
}
return listOfTimezones;