/// <summary> /// Creates a duration from a timespan by discovering the most appropriate <see cref="TimeUnit"/>. /// </summary> /// <param name="timeSpan">The time span.</param> /// <returns>The created <see cref="Duration"/> instance</returns> public static Duration FromTimeSpan(TimeSpan timeSpan) { return(new Duration(timeSpan, TimeHelper.DiscoverUnit(timeSpan))); }
/// <summary> /// Gets a new instance for the same duration expressed in another <see cref="NFluent.TimeUnit"/> /// </summary> /// <param name="newTmeUnit">The target time unit.</param> /// <returns>The new <see cref="Duration"/>.</returns> public Duration ConvertTo(TimeUnit newTmeUnit) { var newDuration = TimeHelper.GetInNanoSeconds(this.RawDuration, this.Unit); return(new Duration(TimeHelper.GetFromNanoSeconds(newDuration, newTmeUnit), newTmeUnit)); }
/// <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; }