richardschneider/net-ipfs-core

IPFS Timespan

Closed this issue · 2 comments

Need parse and format method. IPFS Timespan can have multiple units (1m4.483878032s) as well as "n/a" and "unknown".

From the go spec

A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

Let's use a static class to parse and stringify

public static class Duration
{
   public TimeSpan Parse(string s);
   public string ToString(TimeSpan duration, string zeroValue = "0s");
}