ImanSoftware.DateTimeProvider 1.0.0

dotnet add package ImanSoftware.DateTimeProvider --version 1.0.0
                    
NuGet\Install-Package ImanSoftware.DateTimeProvider -Version 1.0.0
                    
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="ImanSoftware.DateTimeProvider" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ImanSoftware.DateTimeProvider" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ImanSoftware.DateTimeProvider" />
                    
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 ImanSoftware.DateTimeProvider --version 1.0.0
                    
#r "nuget: ImanSoftware.DateTimeProvider, 1.0.0"
                    
#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 ImanSoftware.DateTimeProvider@1.0.0
                    
#: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=ImanSoftware.DateTimeProvider&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ImanSoftware.DateTimeProvider&version=1.0.0
                    
Install as a Cake Tool

ImanSoftware.DateTimeProvider

Version: 1.0.0 | Last Updated: August 2026

A lightweight abstraction over System.DateTime for clean, testable, and dependency-injected date and time access.

ImanSoftware.DateTimeProvider eliminates direct dependencies on DateTime.Now and DateTime.Today by providing a simple, injectable abstraction. This makes your applications easier to test, maintain, and extend.


Installation

Install the package using the .NET CLI:

dotnet add package ImanSoftware.DateTimeProvider

Why DateTimeProvider?

Using DateTime.Now directly introduces hidden dependencies that make unit testing difficult.

Instead of:

var createdAt = DateTime.Now;

Use:

var createdAt = _dateTimeProvider.Now;

Your code becomes deterministic and can easily be tested by mocking the current time.

Benefits include:

  • Improved testability
  • Dependency Injection friendly
  • Clean Architecture compatible
  • Centralized time access
  • Lightweight and dependency-free

Features

  • IDateTimeProvider abstraction
  • Now property
  • Today property
  • CurrentTimeOfDay property
  • ✅ Default implementation using System.DateTime
  • ✅ Easy Dependency Injection registration
  • ✅ Mock-friendly design
  • ✅ Zero configuration

IDateTimeProvider

The core abstraction exposes commonly used date and time values.

Available members:

  • Now
  • Today
  • CurrentTimeOfDay

Example:

public interface IDateTimeProvider
{
    DateTime Now { get; }

    DateTime Today { get; }

    TimeSpan CurrentTimeOfDay { get; }
}

DefaultDateTimeProvider

The package includes a default implementation that wraps System.DateTime.

var provider = new DefaultDateTimeProvider();

var now = provider.Now;

var today = provider.Today;

var time = provider.CurrentTimeOfDay;

Dependency Injection

Register the provider in your application:

services.AddDateTimeProvider();

After registration, IDateTimeProvider can be injected anywhere in your application.


Example

using ImanSoftware.DateTimeProvider;

public class OrderService
{
    private readonly IDateTimeProvider _dateTime;

    public OrderService(IDateTimeProvider dateTime)
    {
        _dateTime = dateTime;
    }

    public void CreateOrder()
    {
        var now = _dateTime.Now;

        // Business logic...
    }
}

Unit Testing

Because the provider is interface-based, replacing it with a mock or fake implementation is straightforward.

var mock = new Mock<IDateTimeProvider>();

mock.Setup(x => x.Now)
    .Returns(new DateTime(2026, 1, 1));

Your business logic can now be tested without relying on the system clock.


Design Goals

  • Clean abstraction
  • High testability
  • Dependency Injection friendly
  • Lightweight
  • Framework independent
  • Minimal API
  • Zero configuration
  • Easy integration
  • Clean Architecture compatible

Requirements

  • .NET Standard 2.0+
  • .NET 6+
  • .NET 7+
  • .NET 8+
  • .NET 9+
  • .NET 10.0+

Author

Iman Estiri

📧 contact.imanestiri@gmail.com

📧 dev.imanestiri@gmail.com

GitHub:

https://github.com/ImanEstiri


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ImanSoftware.DateTimeProvider:

Package Downloads
ImanSoftware.Framework

Umbrella package that bundles all ImanSoftware modules for a unified development experience.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 156 8/3/2026