DotNetThoughts.TimeKeeping 1.3.1

dotnet add package DotNetThoughts.TimeKeeping --version 1.3.1                
NuGet\Install-Package DotNetThoughts.TimeKeeping -Version 1.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetThoughts.TimeKeeping" Version="1.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetThoughts.TimeKeeping --version 1.3.1                
#r "nuget: DotNetThoughts.TimeKeeping, 1.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNetThoughts.TimeKeeping as a Cake Addin
#addin nuget:?package=DotNetThoughts.TimeKeeping&version=1.3.1

// Install DotNetThoughts.TimeKeeping as a Cake Tool
#tool nuget:?package=DotNetThoughts.TimeKeeping&version=1.3.1                

Time Keeping

SystemTime

SystemTime.Now() is a drop-in replacement for DateTimeOffset.UtcNow with a couple of extra features.

You can manipulate time using SystemTime. This is useful for testing, where you want to test how your code behave at different times, or where you want the code to be deterministic. SystemTime works through AsyncLocal, so you do not have to inject a ITimeProvider wherever you need to be able to mock time.

Some example usages:

// Set time to midnight 2024-01-01 (utc I guess) and stop time from moving.
// This means SystemTime.Now() will always return 2024-01-01
SystemTime.Freeze(DateTimeOffset.Parse("2024-01-01"));

// Move time one day forward. Time is still frozen.
// This means SystemTime.Now() will always return 2024-01-02
SystemTime.Advance(TimeSpan.FromDays(1)); 

// Unfreezes time. Time is now 2024-01-02 but time started moving again.
// This means SystemTime.Now() will work as normal, but at an offset to the real-world time.
SystemTime.Thaw();

// Reset time to real world time.
SystemTime.Reset(); 

TimeTravelersClock

TimeTravelersClock is SystemTime but without the AsyncLocal magic. You can instantiate a new TimeTravelsersClock and manipulate it just like SystemTime.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 628 9/23/2024
1.3.0 113 9/22/2024
1.2.0 456 7/6/2024
1.1.0 96 7/5/2024
1.0.0 189 6/16/2024