Table of Contents

Class Duration

Namespace
Ranorex
Assembly
Ranorex.Core.dll

Represents a span of time.

[TypeConverter(typeof(Duration.DurationConverter))]
public sealed class Duration : IFormattable, IComparable<Duration>, IComparable, IEquatable<Duration>
Inheritance
Duration
Implements
Inherited Members

Remarks

This class facilitates creating objects that represent a span of time by providing initializers that take an int (regarded as milliseconds) or a TimeSpan.

Constructors

Duration()

Constructs a new instance and initializes it with the value of Zero.

public Duration()

Duration(int)

Constructs a new instance and initializes it with the given number of milliseconds.

public Duration(int milliseconds)

Parameters

milliseconds int

The number of milliseconds to assign.

Duration(TimeSpan)

Constructs a new instance and initializes it with the value of the given TimeSpan.

public Duration(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

A TimeSpan instance.

Fields

MaxValue

Represents the maximum Duration value. This field is read-only.

public static readonly Duration MaxValue

Field Value

Duration

MinValue

Represents the minimum Duration value. This field is read-only.

public static readonly Duration MinValue

Field Value

Duration

Zero

Represents the zero Duration value. This field is read-only.

public static readonly Duration Zero

Field Value

Duration

Properties

Milliseconds

Gets the number of milliseconds this instance represents.

public int Milliseconds { get; }

Property Value

int

TimeSpan

Gets a TimeSpan representation of this instance.

public TimeSpan TimeSpan { get; }

Property Value

TimeSpan

Methods

Compare(Duration, Duration)

Compares two Duration objects and returns an indication of their relative values.

public static int Compare(Duration d1, Duration d2)

Parameters

d1 Duration

The first duration.

d2 Duration

The second duration.

Returns

int

A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:

ValueMeaning
Less than zerod1 is less than d2.
Zerod1 is equal to d2.
Greater than zerod1 is greater than d2.

CompareTo(Duration)

Compares the current duration with another duration object.

public int CompareTo(Duration other)

Parameters

other Duration

A duration to compare with this instance.

Returns

int

A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:

ValueMeaning
Less than zeroThis instance is less than other.
ZeroThis instance is equal to other.
Greater than zeroThis instance is greater than other.

CompareTo(object)

Compares the current duration with another object of the same type.

public int CompareTo(object obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:

ValueMeaning
Less than zeroThis instance is less than obj.
ZeroThis instance is equal to obj.
Greater than zeroThis instance is greater than obj.

Exceptions

ArgumentException

obj is not of type Duration.

Copy(Duration)

Returns a copy of the specified duration.

public static Duration Copy(Duration d)

Parameters

d Duration

A duration.

Returns

Duration

A copy of duration d.

Equals(Duration)

Indicates whether the current Duration is equal to another Duration.

public bool Equals(Duration other)

Parameters

other Duration

A Duration tom compare this instance with.

Returns

bool

true if the current instance is equal to the other parameter; otherwise, false.

Equals(object)

Returns true if the two objects are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

True if obj is a Duration and represents the same span of time as the current instance.

FromMilliseconds(int)

Returns a new Duration instance initialized by the milliseconds value.

public static Duration FromMilliseconds(int milliseconds)

Parameters

milliseconds int

The number of milliseconds.

Returns

Duration

The new Duration instance.

FromTimeSpan(TimeSpan)

Returns a new Duration instance initialized by the TimeSpan value.

public static Duration FromTimeSpan(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan value.

Returns

Duration

The new Duration instance.

GetHashCode()

Gets a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code.

Parse(string)

Parses the given string and returns a new Duration instance.

public static Duration Parse(string durationString)

Parameters

durationString string

A string representing a duration.

Returns

Duration

A new Duration corresponding to the given string.

Exceptions

ArgumentNullException

If durationString is null.

FormatException

If durationString has an invalid format.

ToMilliseconds(Duration)

Returns the number of milliseconds represented by the Duration instance.

public static int ToMilliseconds(Duration duration)

Parameters

duration Duration

A Duration instance.

Returns

int

Milliseconds.

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string

A string representation of this instance.

Remarks

Calling this method is equivalent to calling ToString(string, IFormatProvider) with parameters (null, InvariantCulture).

ToString(string)

Returns a string representation of this instance.

public string ToString(string format)

Parameters

format string

The string specifying the format to use or null to use the default format.

Returns

string

A string representation of this instance.

Remarks

The following string values are valid for format:

Format StringDescription and Associated Properties
gGeneral format. Replaces the format string by ms, s, m, or t as appropriate regarding the value of this instance.
msMillisecond format.
sSecond format.
hHour format.
dDay format.
tFull format, equal to the format returned by ToString().
If you use capital letters for the string format, the precision of the returned string representation is extended by three decimal digits. Adding '0' as a suffix will result in non-significant zeros to always be displayed, e.g. 'g0'.

ToString(string, IFormatProvider)

Returns a string representation of this instance.

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string

The string specifying the format to use or null to use the default format.

formatProvider IFormatProvider

The IFormatProvider to use or null to obtain the format information from the current locale setting of the operating system.

Returns

string

A string representation of this instance.

Remarks

The following string values are valid for format:

Format StringDescription and Associated Properties
gGeneral format. Replaces the format string by ms, s, m, or t as appropriate regarding the value of this instance.
msMillisecond format.
sSecond format.
hHour format.
dDay format.
tFull format, equal to the format returned by ToString().
If you use capital letters for the string format, the precision of the returned string representation is extended by three decimal digits. Adding '0' as a suffix will result in non-significant zeros to always be displayed, e.g. 'g0'.

ToTimeSpan(Duration)

Returns a TimeSpan value corresponding to the Duration instance.

public static TimeSpan ToTimeSpan(Duration duration)

Parameters

duration Duration

A Duration instance.

Returns

TimeSpan

A TimeSpan value.

TryParse(string, out Duration)

Tries parsing the given string to a Duration instance.

public static bool TryParse(string durationString, out Duration duration)

Parameters

durationString string

A string representing a duration.

duration Duration

When this method returns, contains a Duration instance if parsing succeeded, null otherwise.

Returns

bool

True if parsing succeeded, otherwise false.

Operators

operator +(Duration, Duration)

Adds two values.

public static Duration operator +(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

Duration

The result of adding left and right.

operator +(Duration, int)

Adds two values.

public static Duration operator +(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

Duration

The result of adding left and right.

operator +(Duration, TimeSpan)

Adds two values.

public static Duration operator +(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

Duration

The result of adding left and right.

operator +(int, Duration)

Adds two values.

public static Duration operator +(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

Duration

The result of adding left and right.

operator +(TimeSpan, Duration)

Adds two values.

public static Duration operator +(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

Duration

The result of adding left and right.

operator ==(Duration, Duration)

Returns true if the two Duration instances are equal.

public static bool operator ==(Duration d1, Duration d2)

Parameters

d1 Duration

Duration 1.

d2 Duration

Duration 2.

Returns

bool

True if the two Duration instances are equal, otherwise false.

operator >(Duration, Duration)

Returns whether left is greater than right.

public static bool operator >(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

bool

True if left is greater than right; otherwise false.

operator >(Duration, int)

Returns whether left is greater than right.

public static bool operator >(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

bool

True if left is greater than right; otherwise false.

operator >(Duration, TimeSpan)

Returns whether left is greater than right.

public static bool operator >(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

bool

True if left is greater than right; otherwise false.

operator >(int, Duration)

Returns whether left is greater than right.

public static bool operator >(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

bool

True if left is greater than right; otherwise false.

operator >(TimeSpan, Duration)

Returns whether left is greater than right.

public static bool operator >(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

bool

True if left is greater than right; otherwise false.

operator >=(Duration, Duration)

Returns whether left is greater than or equal to right.

public static bool operator >=(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

bool

True if left is greater than or equal to right; otherwise false.

operator >=(Duration, int)

Returns whether left is greater than or equal to right.

public static bool operator >=(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

bool

True if left is greater than or equal to right; otherwise false.

operator >=(Duration, TimeSpan)

Returns whether left is greater than or equal to right.

public static bool operator >=(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

bool

True if left is greater than or equal to right; otherwise false.

operator >=(int, Duration)

Returns whether left is greater than or equal to right.

public static bool operator >=(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

bool

True if left is greater than or equal to right; otherwise false.

operator >=(TimeSpan, Duration)

Returns whether left is greater than or equal to right.

public static bool operator >=(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

bool

True if left is greater than or equal to right; otherwise false.

implicit operator int(Duration)

Returns the number of milliseconds represented by the Duration instance.

public static implicit operator int(Duration duration)

Parameters

duration Duration

A Duration instance.

Returns

int

Milliseconds.

implicit operator TimeSpan(Duration)

Returns a TimeSpan value corresponding to the Duration instance.

public static implicit operator TimeSpan(Duration duration)

Parameters

duration Duration

A Duration instance.

Returns

TimeSpan

A TimeSpan value.

implicit operator Duration(int)

Returns a new Duration instance initialized by the milliseconds value.

public static implicit operator Duration(int milliseconds)

Parameters

milliseconds int

The number of milliseconds.

Returns

Duration

The new Duration instance.

implicit operator Duration(TimeSpan)

Returns a new Duration instance initialized by the TimeSpan value.

public static implicit operator Duration(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The TimeSpan value.

Returns

Duration

The new Duration instance.

operator !=(Duration, Duration)

Returns true if the two Duration instances are not equal.

public static bool operator !=(Duration d1, Duration d2)

Parameters

d1 Duration

Duration 1.

d2 Duration

Duration 2.

Returns

bool

True if the two Duration instances are not equal, otherwise false.

operator <(Duration, Duration)

Returns whether left is less than right.

public static bool operator <(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

bool

True if left is less than right; otherwise false.

operator <(Duration, int)

Returns whether left is less than right.

public static bool operator <(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

bool

True if left is less than right; otherwise false.

operator <(Duration, TimeSpan)

Returns whether left is less than right.

public static bool operator <(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

bool

True if left is less than right; otherwise false.

operator <(int, Duration)

Returns whether left is less than right.

public static bool operator <(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

bool

True if left is less than right; otherwise false.

operator <(TimeSpan, Duration)

Returns whether left is less than right.

public static bool operator <(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

bool

True if left is less than right; otherwise false.

operator <=(Duration, Duration)

Returns whether left is less than or equal to right.

public static bool operator <=(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

bool

True if left is less than or equal to right; otherwise false.

operator <=(Duration, int)

Returns whether left is less than or equal to right.

public static bool operator <=(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

bool

True if left is less than or equal to right; otherwise false.

operator <=(Duration, TimeSpan)

Returns whether left is less than or equal to right.

public static bool operator <=(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

bool

True if left is less than or equal to right; otherwise false.

operator <=(int, Duration)

Returns whether left is less than or equal to right.

public static bool operator <=(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

bool

True if left is less than or equal to right; otherwise false.

operator <=(TimeSpan, Duration)

Returns whether left is less than or equal to right.

public static bool operator <=(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

bool

True if left is less than or equal to right; otherwise false.

operator *(Duration, double)

Multiplies a duration by the specified factor.

public static Duration operator *(Duration duration, double factor)

Parameters

duration Duration

A duration.

factor double

The factor to multiply the duration with.

Returns

Duration

The duration multiplied by the specified factor.

operator -(Duration, Duration)

Subtracts two values.

public static Duration operator -(Duration left, Duration right)

Parameters

left Duration

A value.

right Duration

Another value.

Returns

Duration

The result of subtracting right from left.

operator -(Duration, int)

Subtracts two values.

public static Duration operator -(Duration left, int right)

Parameters

left Duration

A value.

right int

Another value.

Returns

Duration

The result of subtracting right from left.

operator -(Duration, TimeSpan)

Subtracts two values.

public static Duration operator -(Duration left, TimeSpan right)

Parameters

left Duration

A value.

right TimeSpan

Another value.

Returns

Duration

The result of subtracting right from left.

operator -(int, Duration)

Subtracts two values.

public static Duration operator -(int left, Duration right)

Parameters

left int

A value.

right Duration

Another value.

Returns

Duration

The result of subtracting right from left.

operator -(TimeSpan, Duration)

Subtracts two values.

public static Duration operator -(TimeSpan left, Duration right)

Parameters

left TimeSpan

A value.

right Duration

Another value.

Returns

Duration

The result of subtracting right from left.