using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
using (new FakeLocalTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Etc/GMT+2")))
Assert.AreEqual("Etc/GMT+2", TimeZoneInfo.Local.Id);
Assert.AreEqual(TimeSpan.FromHours(-2), TimeZoneInfo.Local.BaseUtcOffset);
Console.WriteLine("Testing time zone {0}:", TimeZoneInfo.Local.Id);
public static void TestInner()
var freeContent = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(content));
Console.WriteLine(content);
Console.WriteLine(freeContent);
var settings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
Assert.That(JToken.DeepEquals(JsonConvert.DeserializeObject<JToken>(content, settings), JsonConvert.DeserializeObject<JToken>(freeContent, settings)));
static string GetJson() =>
"start": "2020-10-23T15:30:00+00:00"
public class FakeLocalTimeZone : IDisposable
private readonly TimeZoneInfo _actualLocalTimeZoneInfo;
private static void SetLocalTimeZone(TimeZoneInfo timeZoneInfo)
typeof(TimeZoneInfo).AsDynamicType().s_cachedData._localTimeZone = timeZoneInfo;
public FakeLocalTimeZone(TimeZoneInfo timeZoneInfo)
_actualLocalTimeZoneInfo = TimeZoneInfo.Local;
SetLocalTimeZone(timeZoneInfo);
SetLocalTimeZone(_actualLocalTimeZoneInfo);
public static void Main()
Console.WriteLine("Environment version: {0} ({1}), {2}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Namespace, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");