Static class hosting various time helper.
Example #1
0
 /// <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)));
 }
Example #2
0
        /// <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));
        }
Example #3
0
 /// <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;
 }