2 using System.Collections.Generic;
10 public static class TimeSpanExtensions
16 public static string Format(
this TimeSpan TS)
21 return "{0}ns".Build(TS.Ticks * 100);
23 else if (TS.Ticks < 10000)
26 return "{0:0.0}µs".Build(TS.Ticks / 10);
28 else if (TS.TotalMilliseconds < 1000)
30 return "{0:0.0}ms".Build(TS.TotalMilliseconds);
32 else if (TS.TotalSeconds < 60)
34 return "{0:0.000}s".Build(TS.TotalSeconds);
36 else if (TS.TotalMinutes < 60)
38 return "{0:#0}m {1:#0}s".Build(Math.Floor(TS.TotalMinutes), TS.Seconds);
40 else if (TS.TotalHours < 24)
42 return "{0:#0}h {1:#0}m {2:#0}s".Build(Math.Floor(TS.TotalHours), TS.Minutes, TS.Seconds);
53 public static bool IsBetween(
this TimeSpan i, TimeSpan MinValue, TimeSpan MaxValue)
55 return (i >= MinValue && i <= MaxValue);
65 public static TimeSpan Limit(
this TimeSpan i, TimeSpan MinValue, TimeSpan MaxValue)
67 if (i < MinValue)
return MinValue;
68 if (i > MaxValue)
return MaxValue;