CSharpEssentials.Time 3.0.4

dotnet add package CSharpEssentials.Time --version 3.0.4
                    
NuGet\Install-Package CSharpEssentials.Time -Version 3.0.4
                    
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="CSharpEssentials.Time" Version="3.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpEssentials.Time" Version="3.0.4" />
                    
Directory.Packages.props
<PackageReference Include="CSharpEssentials.Time" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharpEssentials.Time --version 3.0.4
                    
#r "nuget: CSharpEssentials.Time, 3.0.4"
                    
#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.
#:package CSharpEssentials.Time@3.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharpEssentials.Time&version=3.0.4
                    
Install as a Cake Addin
#tool nuget:?package=CSharpEssentials.Time&version=3.0.4
                    
Install as a Cake Tool

CSharpEssentials.Time

Testable time abstraction built on .NET TimeProvider. Decouple your code from the system clock for reliable unit testing.

Features

  • IDateTimeProvider — Injectable interface for UtcNow, UtcNowDateTime, UtcNowDate, and UtcNowTime.
  • TimeProvider Integration — Works with .NET's built-in TimeProvider and FakeTimeProvider for testing.
  • DateTime Extensions — Convert DateTime to DateOnly and TimeOnly.

Installation

dotnet add package CSharpEssentials.Time

Usage

DateTimeProvider

using CSharpEssentials.Time;

public class OrderService(IDateTimeProvider time)
{
    public Order CreateOrder()
    {
        return new Order
        {
            CreatedAt = time.UtcNow,
            CreatedDate = time.UtcNowDate
        };
    }
}

Dependency Injection

builder.Services.AddSingleton<TimeProvider>(TimeProvider.System);
builder.Services.AddSingleton<IDateTimeProvider, DateTimeProvider>();

Testing with FakeTimeProvider

using Microsoft.Extensions.Time.Testing;

FakeTimeProvider fakeTime = new();
fakeTime.SetUtcNow(new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero));

IDateTimeProvider provider = new DateTimeProvider(fakeTime);
provider.UtcNow.Year.Should().Be(2025);

Extensions

DateTime now = DateTime.UtcNow;

DateOnly date = now.ToDateOnly();
TimeOnly time = now.ToTimeOnly();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CSharpEssentials.Time:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

CSharpEssentials.Entity

Domain-driven design (DDD) entity base classes and patterns for CSharpEssentials. Provides EntityBase<TId> with soft delete functionality, audit trails, and domain event integration. Essential for building robust domain models with type safety and functional programming principles.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.4 54 5/6/2026
3.0.3 77 5/5/2026
3.0.2 143 5/5/2026
3.0.1 147 5/3/2026
3.0.0 146 5/3/2026
2.1.0 306 11/26/2025
2.0.9 263 9/30/2025
2.0.8 245 9/29/2025
2.0.7 255 9/29/2025
2.0.6 247 9/29/2025
2.0.5 242 9/29/2025
2.0.4 253 9/28/2025
2.0.3 239 9/28/2025
2.0.2 236 9/28/2025
2.0.1 253 9/28/2025
2.0.0 264 9/28/2025