Use a fixed timezone in tests

This commit is contained in:
Tyrrrz
2023-02-12 17:43:45 +02:00
parent f73d07a7c9
commit 2a5e09bf07
3 changed files with 179 additions and 72 deletions

View File

@@ -0,0 +1,14 @@
using System;
using ReflectionMagic;
namespace DiscordChatExporter.Cli.Tests.Utils;
internal static class TimeZoneInfoEx
{
// https://stackoverflow.com/a/63700512/2205454
public static void SetLocal(TimeZoneInfo timeZone) =>
typeof(TimeZoneInfo).AsDynamicType().s_cachedData._localTimeZone = timeZone;
public static void SetLocal(TimeSpan offset) =>
SetLocal(TimeZoneInfo.CreateCustomTimeZone("test-tz", offset, "test-tz", "test-tz"));
}