Net.Bluewalk.DotNetUtils/Extensions/TimeSpanExtensions.cs
/// <summary>
/// Rounds the specific TimeSpan to nearest minute
/// </summary>
/// <param name="input"></param>
/// <param name="minutes"></param>
/// <returns></returns>
Rounds the specific TimeSpan to nearest minute
Rounds the specific TimeSpan to nearest minute
public static TimeSpan RoundToNearestMinutes(this TimeSpan input, int minutes)
        {
            var halfRange = new TimeSpan(0, minutes / 2, 0);
            if (input.Ticks < 0)
                halfRange = halfRange.Negate();
            var totalMinutes = (int)(input + halfRange).TotalMinutes;
            return new TimeSpan(0, totalMinutes - totalMinutes % minutes, 0);
        }
public static TimeSpan RoundToNearestMinutes ( this TimeSpan input , int minutes ) { var halfRange = new TimeSpan ( 0 , minutes / 2 , 0 ) ; if ( input . Ticks < 0 ) halfRange = halfRange . Negate ( ) ; var totalMinutes = ( int ) ( input + halfRange ) . TotalMinutes ; return new TimeSpan ( 0 , totalMinutes - totalMinutes % minutes , 0 ) ; }
Rounds the specific TimeSpan to nearest minute
Rounds the specific TimeSpan to nearest minute
None
TimeSpan
this
minutes
int
None
input
None