Interval
Keeps track of an interval time which can be represented in
Minutes, Seconds or Milliseconds
using System;
namespace NUnit.Framework.Constraints
{
public class Interval
{
internal enum IntervalUnit
{
Minute,
Second,
Millisecond
}
private readonly int _value;
private IntervalUnit _mode;
public TimeSpan AsTimeSpan { get; set; }
public Interval InMinutes {
get {
AsTimeSpan = TimeSpan.FromMinutes((double)_value);
_mode = IntervalUnit.Minute;
return this;
}
}
public Interval InSeconds {
get {
AsTimeSpan = TimeSpan.FromSeconds((double)_value);
_mode = IntervalUnit.Second;
return this;
}
}
public Interval InMilliseconds {
get {
AsTimeSpan = TimeSpan.FromMilliseconds((double)_value);
_mode = IntervalUnit.Millisecond;
return this;
}
}
public bool IsNotZero => _value != 0;
public Interval(int value)
{
_value = value;
_mode = IntervalUnit.Millisecond;
AsTimeSpan = TimeSpan.FromMilliseconds((double)value);
}
public override string ToString()
{
return string.Format("{0} {1}{2}", _value, _mode.ToString().ToLower(), (_value > 1) ? "s" : string.Empty);
}
}
}