DurationMancer 1.1.0

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

Build and analyze Quality Gate Status NuGet Version

DurationMancer

DurationMancer is a simple library that provides a flexible time parser that understands both technical and natural language inputs. You can use these formats wherever a (negative) time duration is required, and you don't want to deal with the hassle of parsing strings yourself.

Supported Formats

Standard Duration Format

This format is best for precise, structured input.

It follows the pattern:
[-][days.]HH:mm:ss[.milliseconds]

Component Format Range / Description
Negative sign - Optional. Defines that the value provided is negative.
Days d. Optional. Any number of digits followed by a dot.
Hours HH Required. 00 to 23.
Minutes mm Required. 00 to 59.
Seconds ss Required. 00 to 59.
Milliseconds .fff Optional. Up to 3 digits following a dot.

Examples:

  • 12:30:00 → 12 hours, 30 minutes
  • 1.05:00:00 → 1 day, 5 hours
  • 00:00:45.500 → 45.5 seconds
  • -00:00:05 → -5 seconds

Human-Readable Format

This format is ideal for quick CLI input. You can mix and match units using full names or shorthand.

ℹ️ Please note that a negative value is defined by a minus sign (-) in the first position of the entire string to be parse.

Supported Units
Unit Keywords (Case-Insensitive)
Negative sign -
Days d, day, days
Hours h, hour, hours
Minutes m, min, minute, minutes
Seconds s, sec, second, seconds
Milliseconds ms, millisecond, milliseconds
Key Features
  • Decimal Support: You can use decimals for larger units (e.g., 1.5h for 1 hour and 30 minutes).
  • Flexible Spacing: 1h30m and 1 h 30 m are both valid.
  • Automatic Rounding: All inputs are rounded to the nearest millisecond.

Examples:

  • 1d 12h → 1.12:00:00
  • 5m 30s → 00:05:30
  • 1.5 hours → 01:30:00
  • 100 ms → 00:00:00.100
  • 2 days 4 h 15 m 30 s → 2.04:15:30
  • -1m → -00:01:00
  • -1m 13s → -00:01:13

Usage

The usage is straightforward, like shown in the examples below.

Standard Duration Format

// Example 1: TryParse Days, hours, minutes, and seconds
string input1 = "1.05:00:00";
bool isSuccessfulParsed = DurationTimeParser.TryParse(input1, out TimeSpan result1);
// result1 == new TimeSpan(days: 1, hours: 5, minutes: 0, seconds: 0)
// result1 -> 1.05:00:00

// Example 2: Parse Seconds with milliseconds
string input2 = "00:00:45.500";
TimeSpan result2 = DurationTimeParser.Parse(input2);
// result2 == new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 45, milliseconds: 500)
// result2 -> 00:00:45.500

Human-readable Format

// Example 1: Mix of full words and shorthand
string input1 = "2days 4h 15m 30s";
bool isSuccessfulParsed = DurationTimeParser.TryParse(input1, out TimeSpan result1);
// result1 == new TimeSpan(days: 2, hours: 4, minutes: 15, seconds: 30)
// result1 -> 2.04:15:30

// Example 2: Decimal values with flexible spacing
string input2 = "1.5 hours 100ms";
TimeSpan result2 = DurationTimeParser.Parse(input2);
// result2 == new TimeSpan(days: 0, hours: 1, minutes: 30, seconds: 0, milliseconds: 100)
// result2 -> 01:30:00.100

Benchmarks

For detailed benchmark results, please check the Benchmarks page in the Wiki.

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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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.1.0 37 3/8/2026
1.0.0 84 2/22/2026