GoDuration 0.3.0
dotnet add package GoDuration --version 0.3.0
NuGet\Install-Package GoDuration -Version 0.3.0
<PackageReference Include="GoDuration" Version="0.3.0" />
<PackageVersion Include="GoDuration" Version="0.3.0" />
<PackageReference Include="GoDuration" />
paket add GoDuration --version 0.3.0
#r "nuget: GoDuration, 0.3.0"
#:package GoDuration@0.3.0
#addin nuget:?package=GoDuration&version=0.3.0
#tool nuget:?package=GoDuration&version=0.3.0
GoDuration
A C# library that parses Go-style duration strings into TimeSpan values, and formats TimeSpan values back to Go-style duration strings.
Packages
| Package | Purpose |
|---|---|
GoDuration |
Core parser and formatter. Returns TimeSpan. |
GoDuration.NodaTime |
Parser and formatter that returns NodaTime.Duration. |
All packages target netstandard2.0, net8.0, and net10.0.
Install
dotnet add package GoDuration
Use
using GoDuration;
TimeSpan value = GoDurationConverter.Parse("1h30m45s");
string text = GoDurationConverter.Format(value);
The parser accepts the same units as Go: ns, us, µs, μs, ms, s, m, and h.
Format options
Use DurationFormatOptions to change the output format:
var options = new DurationFormatOptions
{
OmitZeroUnits = true,
IncludePositiveSign = true,
MicrosecondSymbol = MicrosecondSymbol.Ascii,
};
string text = GoDurationConverter.Format(TimeSpan.FromHours(1), options);
Direct nanosecond access
Both packages sit on top of GoDurationReader and GoDurationWriter. Use these when
you want raw nanosecond counts and no value-type conversion:
using GoDuration;
if (GoDurationReader.TryRead("1h30m", out long nanoseconds, out _))
{
string text = GoDurationWriter.Write(nanoseconds);
}
Value range
The accepted range matches Go's time.Duration: signed int64 nanoseconds (about ±292 years).
Parse rejects strings outside this range. Format throws OverflowException for TimeSpan
values outside this range.
NodaTime
For NodaTime.Duration values, use the GoDuration.NodaTime package:
using GoDuration.NodaTime;
using NodaTime;
Duration value = GoDurationConverter.Parse("1h30m45s");
string text = GoDurationConverter.Format(value);
See GoDuration.NodaTime.
Build
The build uses Fallout. Run one of the scripts at the repository root:
./build.sh Test
./build.sh Pack
Targets: Clean, Restore, Compile, Test, Pack, BundleZip, PublishNuGet, PublishGitHubRelease, Publish.
License
MIT. See LICENSE.
| Product | Versions 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 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 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. |
| .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 was computed. 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. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on GoDuration:
| Package | Downloads |
|---|---|
|
GoDuration.SystemTextJson
System.Text.Json TimeSpan converter that reads and writes Go-style duration strings (e.g. "300ms", "1h30m") through the GoDuration parser and formatter. |
|
|
GoDuration.NewtonsoftJson
Newtonsoft.Json TimeSpan converter that reads and writes Go-style duration strings (e.g. "300ms", "1h30m") through the GoDuration parser and formatter. |
|
|
GoDuration.YamlDotNet
YamlDotNet TimeSpan type converter that reads and writes Go-style duration strings (e.g. "300ms", "1h30m") through the GoDuration parser and formatter. |
|
|
GoDuration.NodaTime
Parses and formats Go-style duration strings (e.g. "300ms", "-1.5h", "2h45m") to and from NodaTime.Duration through the GoDuration parser and formatter. |
GitHub repositories
This package is not used by any popular GitHub repositories.