25 public class AcDuration : IFormattable, IEquatable<AcDuration>, IComparable<AcDuration>, IComparable
42 return (rhs != null) ? rhs._ts :
new TimeSpan();
53 #region Equality comparison
63 if (ReferenceEquals(other, null))
return false;
64 if (ReferenceEquals(
this, other))
return true;
65 return _ts.Equals(other._ts);
72 public override bool Equals(
object other)
74 if (ReferenceEquals(other, null))
return false;
75 if (ReferenceEquals(
this, other))
return true;
76 if (GetType() != other.GetType())
return false;
86 return _ts.GetHashCode();
91 #region Order comparison
105 result = _ts.CompareTo(other._ts);
116 int IComparable.CompareTo(
object other)
119 throw new ArgumentException(
"Argument is not an AcDuration",
"other");
127 public string ToString(
string format, IFormatProvider provider)
142 if (provider != null)
144 ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter;
146 return fmt.Format(format,
this, provider);
149 if (String.IsNullOrEmpty(format))
152 switch (format.ToUpperInvariant())
156 string hours = $
"{_ts.Hours:D2}";
157 string minutes = $
"{_ts.Minutes:D2}";
158 string seconds = $
"{_ts.Seconds:D2}";
161 elapsedTime = $
"{_ts.Days} {((_ts.Days == 1) ? "day
" : "days
")}, {hours}:{minutes}:{seconds}";
163 elapsedTime = $
"{hours}:{minutes}:{seconds}";
167 return $
"{_ts.Hours:D2}";
169 return $
"{_ts.Minutes:D2}";
171 return $
"{_ts.Seconds:D2}";
173 return $
"{_ts.Days} {((_ts.Days == 1) ? "day
" : "days
")}";
175 throw new FormatException($
"The {format} format string is not supported.");
180 public string ToString(
string format)
override bool Equals(object other)
Overridden to determine equality.
Wrapper around TimeSpan so we can return our own formatted elapsed time string and still sort correct...
bool Equals(AcDuration other)
IEquatable implementation to determine the equality of instances of type AcDuration.
int CompareTo(AcDuration other)
Generic IComparable implementation (default) for comparing AcDuration objects to sort by timespan...
string ToString(string format, IFormatProvider provider)
The ToString implementation.
override int GetHashCode()
Override appropriate for type AcDuration.
AcDuration(TimeSpan ts)
Constructor.