/// <summary> /// Checks if the duration is equal to another one. /// </summary> /// <param name="other">The duration to compare to.</param> /// <returns>True if both Durations represents the same duration.</returns> public bool Equals(Duration other) { var firstFactor = TimeHelper.GetConversionFactor(this.Unit); var secondFactor = TimeHelper.GetConversionFactor(other.Unit); return(Math.Abs(this.RawDuration - (other.RawDuration / firstFactor * secondFactor)) < 0.001); }
/// <summary> /// Checks if duration a is greater than duration b. /// </summary> /// <param name="a"> /// First operand. /// </param> /// <param name="b"> /// Second operand. /// </param> /// <returns> /// True if a is greater than b. /// </returns> public static bool operator >(Duration a, Duration b) { var firstFactor = TimeHelper.GetConversionFactor(a.Unit); var secondFactor = TimeHelper.GetConversionFactor(b.Unit); return(a.RawDuration > (b.RawDuration / firstFactor * secondFactor)); }
/// <summary> /// Initializes a new instance of the <see cref="Duration"/> struct. /// </summary> /// <param name="timeSpan">The time span.</param> /// <param name="unit">The time unit.</param> public Duration(TimeSpan timeSpan, TimeUnit unit) { this.rawDuration = timeSpan.TotalMilliseconds * TimeHelper.GetConversionFactor(TimeUnit.Milliseconds) / TimeHelper.GetConversionFactor(unit); this.timeUnit = unit; }