Table of Contents

Class TimeSpanExtensions

Namespace
Plugin.BaseTypeExtensions
Assembly
Plugin.BaseTypeExtensions.dll

Provides extension methods for TimeSpan operations and utility functions.

public static class TimeSpanExtensions
Inheritance
TimeSpanExtensions
Inherited Members

Methods

Average(IEnumerable<TimeSpan>)

Calculates the average of a collection of TimeSpans.

public static TimeSpan Average(this IEnumerable<TimeSpan> timeSpans)

Parameters

timeSpans IEnumerable<TimeSpan>

The collection of TimeSpans.

Returns

TimeSpan

The average TimeSpan.

Exceptions

ArgumentNullException

Thrown when timeSpans is null.

InvalidOperationException

Thrown when the collection is empty.

Divide(TimeSpan, double)

Divides the TimeSpan by a divisor.

public static TimeSpan Divide(this TimeSpan timeSpan, double divisor)

Parameters

timeSpan TimeSpan

The TimeSpan to divide.

divisor double

The division divisor.

Returns

TimeSpan

A new TimeSpan that is the result of the division.

Exceptions

DivideByZeroException

Thrown when divisor is zero.

IsGreaterThan(TimeSpan, TimeSpan)

Determines whether the TimeSpan is greater than another TimeSpan.

public static bool IsGreaterThan(this TimeSpan timeSpan, TimeSpan other)

Parameters

timeSpan TimeSpan

The TimeSpan to compare.

other TimeSpan

The TimeSpan to compare against.

Returns

bool

True if the TimeSpan is greater than the other; otherwise, false.

IsLessThan(TimeSpan, TimeSpan)

Determines whether the TimeSpan is less than another TimeSpan.

public static bool IsLessThan(this TimeSpan timeSpan, TimeSpan other)

Parameters

timeSpan TimeSpan

The TimeSpan to compare.

other TimeSpan

The TimeSpan to compare against.

Returns

bool

True if the TimeSpan is less than the other; otherwise, false.

IsNegative(TimeSpan)

Determines whether the TimeSpan is negative.

public static bool IsNegative(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to check.

Returns

bool

True if the TimeSpan is negative; otherwise, false.

IsPositive(TimeSpan)

Determines whether the TimeSpan is positive.

public static bool IsPositive(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to check.

Returns

bool

True if the TimeSpan is positive; otherwise, false.

IsZero(TimeSpan)

Determines whether the TimeSpan is zero.

public static bool IsZero(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to check.

Returns

bool

True if the TimeSpan is zero; otherwise, false.

Multiply(TimeSpan, double)

Multiplies the TimeSpan by a factor.

public static TimeSpan Multiply(this TimeSpan timeSpan, double factor)

Parameters

timeSpan TimeSpan

The TimeSpan to multiply.

factor double

The multiplication factor.

Returns

TimeSpan

A new TimeSpan that is the result of the multiplication.

RoundTo(TimeSpan, TimeSpan)

Rounds the TimeSpan to the nearest specified interval.

public static TimeSpan RoundTo(this TimeSpan timeSpan, TimeSpan interval)

Parameters

timeSpan TimeSpan

The TimeSpan to round.

interval TimeSpan

The interval to round to.

Returns

TimeSpan

A TimeSpan rounded to the nearest interval.

Exceptions

ArgumentOutOfRangeException

Thrown when interval is zero or negative.

RoundToDays(TimeSpan)

Rounds the TimeSpan to the nearest day.

public static TimeSpan RoundToDays(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to round.

Returns

TimeSpan

A TimeSpan rounded to the nearest day.

RoundToHours(TimeSpan)

Rounds the TimeSpan to the nearest hour.

public static TimeSpan RoundToHours(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to round.

Returns

TimeSpan

A TimeSpan rounded to the nearest hour.

RoundToMinutes(TimeSpan)

Rounds the TimeSpan to the nearest minute.

public static TimeSpan RoundToMinutes(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to round.

Returns

TimeSpan

A TimeSpan rounded to the nearest minute.

ToBusinessDays(TimeSpan)

Converts the TimeSpan to business days (excluding weekends).

public static int ToBusinessDays(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to convert.

Returns

int

The approximate number of business days.

ToHumanReadable(TimeSpan)

Converts the TimeSpan to a human-readable format with approximate values.

public static string ToHumanReadable(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to format.

Returns

string

A human-readable string with approximate values (e.g., "about 2 hours").

ToReadableString(TimeSpan)

Converts the TimeSpan to a human-readable string format.

public static string ToReadableString(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to format.

Returns

string

A human-readable string representation.

ToShortString(TimeSpan)

Converts the TimeSpan to a short string format.

public static string ToShortString(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to format.

Returns

string

A short string representation (e.g., "1d 2h 30m").

ToWeeks(TimeSpan)

Converts the TimeSpan to weeks (integer part only).

public static int ToWeeks(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to convert.

Returns

int

The number of complete weeks.

ToWeeksExact(TimeSpan)

Converts the TimeSpan to weeks with decimal precision.

public static double ToWeeksExact(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan to convert.

Returns

double

The number of weeks as a double.