Home

Awesome

A very small package that helps to fake (a.k.a. mock) system TimeZone.

This package may be useful for testing DateTime and local/UTC conversions.

NuGet

Usage

In order to use the library, wrap FakeLocalTimeZone in using keyword and provide local time zone ID that you want to switch to.

Example:

using (new FakeLocalTimeZone(TimeZoneInfo.FindSystemTimeZoneById("UTC+12")))
{
    var localDateTime = new DateTime(2020, 12, 31, 23, 59, 59, DateTimeKind.Local);
    var utcDateTime = TimeZoneInfo.ConvertTimeToUtc(localDateTime);

    Assert.That(TimeZoneInfo.Local.Id, Is.EqualTo("UTC+12")); // ✅ Assertion passes
    Assert.That(localDateTime, Is.EqualTo(utcDateTime.AddHours(12))); // ✅ Assertion passes
}

// Now, TimeZoneInfo.Local is the one before setup

Supported frameworks

For the main library, following frameworks are supported:

The library has been tested with the following frameworks:

Remarks