jaytwo.TimeExpression 0.1.0-beta-20251031003304

This is a prerelease version of jaytwo.TimeExpression.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package jaytwo.TimeExpression --version 0.1.0-beta-20251031003304
                    
NuGet\Install-Package jaytwo.TimeExpression -Version 0.1.0-beta-20251031003304
                    
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="jaytwo.TimeExpression" Version="0.1.0-beta-20251031003304" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="jaytwo.TimeExpression" Version="0.1.0-beta-20251031003304" />
                    
Directory.Packages.props
<PackageReference Include="jaytwo.TimeExpression" />
                    
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 jaytwo.TimeExpression --version 0.1.0-beta-20251031003304
                    
#r "nuget: jaytwo.TimeExpression, 0.1.0-beta-20251031003304"
                    
#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 jaytwo.TimeExpression@0.1.0-beta-20251031003304
                    
#: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=jaytwo.TimeExpression&version=0.1.0-beta-20251031003304&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=jaytwo.TimeExpression&version=0.1.0-beta-20251031003304&prerelease
                    
Install as a Cake Tool

jaytwo.TimeExpression

NuGet Version NuGet Downloads License: MIT

jaytwo.TimeExpression provides human-readable time formatting utilities modeled after Go’s time.Duration output, with optional ASCII-safe output and configurable settings.

View source on GitHub →


🧭 Overview

This package lets you format .NET TimeSpan values using Go-style duration strings — the same format returned by Go’s time.Duration.String(). It’s small, dependency-free, and useful for readable timing logs, metrics, headers, and JSON.

Examples

TimeSpan Go-style output ASCII-safe output
TimeSpan.Zero 0s 0s
TimeSpan.FromTicks(1) 100ns 100ns
TimeSpan.FromMilliseconds(1.23) 1.23ms 1.23ms
TimeSpan.FromSeconds(9.8) 9.8s 9.8s
TimeSpan.FromMinutes(1.5) 1m30s 1m30s
TimeSpan.FromHours(2) 2h0m0s 2h0m0s

Why is ASCII-safe such a big deal? The first use of this package was adding human-readable response times to HTTP headers for easier debugging. Everything was working great until you get that a sub-millisecond response time, and suddenly the middleware crashed.

Turns out the µ in µs was the problem (HTTP headers must be ASCII-only).


✨ Features

  • ✅ Go-compatible duration syntax (1h2m3.5s, 1.23ms, 500µs, 100ns)
  • ⚙️ Canonical or ASCII-safe microseconds (µs → us)
  • 🪶 Tiny footprint, no dependencies

📦 Installation

Add via NuGet:

PM> Install-Package jaytwo.TimeExpression

Or using the .NET CLI:

dotnet add package jaytwo.TimeExpression

🚀 Usage

Basic usage

using jaytwo.TimeExpression.Golang;

var ts = TimeSpan.FromSeconds(90);

Console.WriteLine(GoDuration.ToGoString(ts));      // 1m30s
Console.WriteLine(GoDuration.ToAsciiString(ts));   // 1m30s (ASCII-safe)

With settings

var settings = new GolangDurationFormatSettings(asciiMicroseconds: true);
var s = GoDuration.ToString(TimeSpan.FromMicroseconds(12.3), settings);
// → "12.3us"

Direct formatter usage

var formatter = new GolangDurationFormatter(GolangDurationFormatSettings.AsciiSafe);
var str = formatter.ToGoString(TimeSpan.FromMilliseconds(1.5));
// → "1.5ms"

🧩 API Summary

Type Description
GoDuration Static helper class providing simple entry points like ToGoString() and ToAsciiString().
GolangDurationFormatter Core formatter implementing Go-style output.

🧪 Example Outputs

GoDuration.ToGoString(TimeSpan.Zero);                    // 0s
GoDuration.ToGoString(TimeSpan.FromTicks(1));            // 100ns
GoDuration.ToGoString(TimeSpan.FromTicks(10));           // 1µs
GoDuration.ToAsciiString(TimeSpan.FromTicks(10));        // 1us
GoDuration.ToGoString(TimeSpan.FromMilliseconds(1.23));  // 1.23ms
GoDuration.ToGoString(TimeSpan.FromSeconds(9.8));        // 9.8s
GoDuration.ToGoString(TimeSpan.FromMinutes(1.5));        // 1m30s
GoDuration.ToGoString(TimeSpan.FromHours(2));            // 2h0m0s
GoDuration.ToGoString(TimeSpan.FromDays(1));             // 24h0m0s

Made with ♥ by Jake — Licensed under the MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on jaytwo.TimeExpression:

Package Downloads
jaytwo.Ergonomics.Ado

Transparent ergonomic extensions for base ADO.NET objects.

jaytwo.DistributedLocks

Package Description

jaytwo.AspNetCore.ResponseTime

Package Description

jaytwo.Ergonomics.Logging

Ergonomic structured logging builders for Microsoft.Extensions.Logging.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta-20251102202452 234 11/3/2025
0.1.0-beta-20251101211754 402 11/2/2025
0.1.0-beta-20251101163444 153 11/1/2025
0.1.0-beta-20251101160839 153 11/1/2025
0.1.0-beta-20251031003304 188 10/31/2025