fix: Cleans up core code (#1187)
**Only one functional change** * Fixes a bug in LogFactory where `Warning` is being logged as `Information` Non-functional changes: * Updates/Fixes copyright headers * Removes namespace scopes for core files. View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
parent
0138d40bda
commit
f268d5d4e2
262 changed files with 28527 additions and 28646 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2021 - ModernUO Development Team *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: TimeZoneHandler.cs *
|
||||
* *
|
||||
|
|
@ -19,9 +19,9 @@ using System.IO;
|
|||
using System.Runtime.CompilerServices;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
/**
|
||||
namespace Server;
|
||||
|
||||
/**
|
||||
* TimeZoneHandler provides a cross platform compatible way to handle system timezones.
|
||||
*
|
||||
* By default the system timezone is used.
|
||||
|
|
@ -37,44 +37,43 @@ namespace Server
|
|||
* Example:
|
||||
* "system.localTimeZone": "Europe/Lisbon"
|
||||
*/
|
||||
public static class TimeZoneHandler
|
||||
public static class TimeZoneHandler
|
||||
{
|
||||
private static readonly Dictionary<string, TimeZoneInfo> _timeZoneById = new();
|
||||
public static TimeZoneInfo SystemTimeZone { get; private set; }
|
||||
|
||||
static 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)
|
||||
{
|
||||
var timezones = JsonConfig.Deserialize<TimeZoneWithRegions[]>(Path.Combine(Core.BaseDirectory, "Data/timezones.json"));
|
||||
foreach (var tz in timezones)
|
||||
// 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 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;
|
||||
// Get the timezone by region if we are on linux
|
||||
tzInfo ??= TimeZoneInfo.FindSystemTimeZoneById(region);
|
||||
_timeZoneById[region] = tzInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
var tzId = ServerConfiguration.GetSetting("system.localTimeZone", TimeZoneInfo.Local.Id);
|
||||
SystemTimeZone = FindTimeZoneById(tzId);
|
||||
_timeZoneById[tz.TimeZone] = tzInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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];
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static TimeZoneInfo FindTimeZoneById(string id) => _timeZoneById[id];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DateTime ToSystemLocalTime(this DateTime date) =>
|
||||
TimeZoneInfo.ConvertTimeFromUtc(date, SystemTimeZone);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DateTime ToSystemLocalTime(this DateTime date) =>
|
||||
TimeZoneInfo.ConvertTimeFromUtc(date, SystemTimeZone);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue