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:
Kamron Batman 2023-05-19 16:40:06 -07:00 committed by GitHub
parent 0a9bfb0558
commit f92d821168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 1218 deletions

View file

@ -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

View file

@ -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) =>

View file

@ -15,7 +15,7 @@ ModernUO [![Discord](https://img.shields.io/discord/751317910504603701?logo=disc
## Requirements
#### Supported Operating Systems
[![Windows 10/11/2016/2019/2022](https://img.shields.io/badge/-server%202022-0078D6?logo=windows&logoColor=0078D6&labelColor=222222)](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
[![Windows 10/11/2019/2022](https://img.shields.io/badge/-server%202022-0078D6?logo=windows&logoColor=0078D6&labelColor=222222)](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
![MacOS 10.15+](https://img.shields.io/badge/-ventura-222222?logo=apple&logoColor=white&labelColor=222222)
[![Debian 10+](https://img.shields.io/badge/-bullseye-A81D33?logo=debian&logoColor=A81D33&labelColor=222222)](https://www.debian.org/distrib/)
[![Ubuntu 16+ LTS](https://img.shields.io/badge/-22LTS-E95420?logo=ubuntu&logoColor=E95420&labelColor=222222)](https://ubuntu.com/download/server)
@ -30,11 +30,11 @@ ModernUO [![Discord](https://img.shields.io/discord/751317910504603701?logo=disc
[![Arch](https://img.shields.io/badge/-Arch-1793D1?logo=archlinux&logoColor=1793D1&labelColor=222222)](https://archlinux.org/download/)
#### Running the server
[![.NET](https://img.shields.io/badge/-7.0.3-5C2D91?logo=.NET&logoColor=white&labelColor=222222)](https://dotnet.microsoft.com/download/dotnet/7.0)
[![.NET](https://img.shields.io/badge/-7.0.4-5C2D91?logo=.NET&logoColor=white&labelColor=222222)](https://dotnet.microsoft.com/download/dotnet/7.0)
#### Development
[![git](https://img.shields.io/badge/-git-F05032?logo=git&logoColor=F05032&labelColor=222222)](https://git-scm.com/downloads)
[![.NET](https://img.shields.io/badge/-%207.0.201%20SDK-5C2D91?logo=.NET&logoColor=white&labelColor=222222)](https://dotnet.microsoft.com/download/dotnet/7.0)
[![.NET](https://img.shields.io/badge/-%207.0.202%20SDK-5C2D91?logo=.NET&logoColor=white&labelColor=222222)](https://dotnet.microsoft.com/download/dotnet/7.0)
#### Supported IDEs
@ -57,8 +57,8 @@ ModernUO [![Discord](https://img.shields.io/discord/751317910504603701?logo=disc
## Building/Publishing
- Run `./publish.cmd [release|debug (default: release)] [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)