fix: Fixes timezone issue (#1388)
### Summary Removes the timezone specific logic in favor of globalization non-invariance. This should fix culture issues too.
This commit is contained in:
parent
0a9bfb0558
commit
f92d821168
4 changed files with 9 additions and 1218 deletions
|
|
@ -37,7 +37,7 @@
|
|||
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
|
||||
<SelfContained>false</SelfContained>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<InvariantGlobalization>false</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true' AND '$(IsX64)'=='true' AND '$(RuntimeIdentifier)'==''">
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: TimeZoneHandler.cs *
|
||||
* *
|
||||
|
|
@ -14,74 +14,22 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Json;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server;
|
||||
|
||||
/**
|
||||
* TimeZoneHandler provides a cross platform compatible way to handle system timezones.
|
||||
*
|
||||
* By default the system timezone is used.
|
||||
* To manually configure the local timezone add the following setting to modernuo.json:
|
||||
* "system.localTimeZone": "Pacific Standard Time"
|
||||
* All valid timezones can be found in the Distribution/Data/timezones.json file.
|
||||
*
|
||||
* Notes for timezones.json:
|
||||
* By default, Windows will use the values in the "timezone" property.
|
||||
* By default, Unix/MacOS will use the values in the "region" property.
|
||||
* system.localTimeZone can be either timezone or a region.
|
||||
*
|
||||
* Example:
|
||||
* "system.localTimeZone": "Europe/Lisbon"
|
||||
*/
|
||||
public static class TimeZoneHandler
|
||||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(TimeZoneHandler));
|
||||
|
||||
private static readonly Dictionary<string, TimeZoneInfo> _timeZoneById = new();
|
||||
public static TimeZoneInfo SystemTimeZone { get; private set; }
|
||||
|
||||
static TimeZoneHandler()
|
||||
{
|
||||
var timezones = JsonConfig.Deserialize<TimeZoneWithRegions[]>(Path.Combine(Core.BaseDirectory, "Data/timezones.json"));
|
||||
foreach (var tz in timezones)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the timezone if we are on Windows
|
||||
var tzInfo = Core.IsWindows ? TimeZoneInfo.FindSystemTimeZoneById(tz.TimeZone) : null;
|
||||
|
||||
foreach (var region in tz.Regions)
|
||||
{
|
||||
// Get the timezone by region if we are on linux
|
||||
tzInfo ??= TimeZoneInfo.FindSystemTimeZoneById(region);
|
||||
_timeZoneById[region] = tzInfo;
|
||||
}
|
||||
|
||||
_timeZoneById[tz.TimeZone] = tzInfo;
|
||||
}
|
||||
catch (TimeZoneNotFoundException e)
|
||||
{
|
||||
logger.Warning(e, $"Timezone '{tz.TimeZone}' was not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
var tzId = ServerConfiguration.GetSetting("system.localTimeZone", TimeZoneInfo.Local.Id);
|
||||
SystemTimeZone = FindTimeZoneById(tzId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross platform version of TimeZoneInfo.FindSystemTimeZoneById
|
||||
*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static TimeZoneInfo FindTimeZoneById(string id) => _timeZoneById[id];
|
||||
public static TimeZoneInfo FindTimeZoneById(string id) => TimeZoneInfo.FindSystemTimeZoneById(id);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DateTime ToSystemLocalTime(this DateTime date) =>
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -15,7 +15,7 @@ ModernUO [](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
|
||||
[](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
|
||||

|
||||
[](https://www.debian.org/distrib/)
|
||||
[](https://ubuntu.com/download/server)
|
||||
|
|
@ -30,11 +30,11 @@ ModernUO [](https://archlinux.org/download/)
|
||||
|
||||
#### Running the server
|
||||
[](https://dotnet.microsoft.com/download/dotnet/7.0)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/7.0)
|
||||
|
||||
#### Development
|
||||
[](https://git-scm.com/downloads)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/7.0)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/7.0)
|
||||
|
||||
#### Supported IDEs
|
||||
|
||||
|
|
@ -57,8 +57,8 @@ ModernUO [] [os] [arch (default: x64)]`
|
||||
- `os` - [Supported operating systems](https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md)
|
||||
- `win` - Windows 10/11/2016/2019/2022
|
||||
- `osx` - MacOS 10.15/11/12/13 (Catalina, Big Sur, Monterey, Ventura)
|
||||
- `win` - Windows 10/11/2019/2022
|
||||
- `osx` - MacOS 11/12/13 (Big Sur, Monterey, Ventura)
|
||||
- `linux` - Linux
|
||||
- `arch`
|
||||
- `x64` - Intel 64-bit
|
||||
|
|
@ -83,7 +83,7 @@ apt-get install -y libicu-dev libz-dev zstd libargon2-dev tzdata
|
|||
|
||||
## Running the Server
|
||||
- Follow the [publish](https://github.com/modernuo/ModernUO#publishing-builds) instructions
|
||||
- Run `ModernUO.exe` or `dotnet ModernUO.dll` from the `Distribution` directory on the server
|
||||
- Run `ModernUO.exe` or `dotnet ModernUO.dll` from the `Distribution` directory on the
|
||||
|
||||
## Troubleshooting / FAQ
|
||||
- See [FAQ](./FAQ.md)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue