Struct Duration
Represents a fixed (and calendar-independent) length of time.
Since 1.0.x
Availability net35-Client, PCL
Implements
IComparable
IXmlSerializable
IFormattable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct Duration : IEquatable<Duration>, IComparable<Duration>, IComparable, IXmlSerializable, IFormattable, ISerializable
Fields
Epsilon
Represents the
Duration value equals to 1 tick; the smallest amount by which an instant can vary.
This field is read-only.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly Duration Epsilon
Field Value
Zero
Represents the zero
Duration value.
This field is read-only.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly Duration Zero
Field Value
Properties
Ticks
The total number of ticks in the duration.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public long Ticks { get; }
Property Value
Methods
Add(Duration, Duration)
Adds one duration to another. Friendly alternative to operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Add(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the sum of the given values. |
CompareTo(Duration)
Compares the current object with another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int CompareTo(Duration other)
Parameters
Type |
Name |
Description |
Duration |
other |
An object to compare with this object. |
Returns
Type |
Description |
Int32 |
A 32-bit signed integer that indicates the relative order of the objects being compared.
The return value has the following meanings:
Value | Meaning |
---|
< 0 | This object is less than the other parameter. | 0 | This object is equal to other . | > 0 | This object is greater than other . |
|
Divide(Duration, Int64)
Divides a duration by a number. Friendly alternative to operator/()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Divide(Duration left, long right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Int64 |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the result of dividing left by
right . |
Equals(Duration)
Indicates whether the current object is equal to another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public bool Equals(Duration other)
Parameters
Type |
Name |
Description |
Duration |
other |
An object to compare with this object. |
Returns
Type |
Description |
Boolean |
true if the current object is equal to the other parameter;
otherwise, false.
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The System.Object to compare with this instance. |
Returns
Type |
Description |
Boolean |
true if the specified System.Object is equal to this instance;
otherwise, false .
|
Overrides
System.ValueType.Equals(System.Object)
FromHours(Int64)
Returns a
Duration that represents the given number of hours.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromHours(long hours)
Parameters
Type |
Name |
Description |
Int64 |
hours |
The number of hours. |
Returns
FromMilliseconds(Int64)
Returns a
Duration that represents the given number of milliseconds.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromMilliseconds(long milliseconds)
Parameters
Type |
Name |
Description |
Int64 |
milliseconds |
The number of milliseconds. |
Returns
Type |
Description |
Duration |
A Duration representing the given number of milliseconds. |
FromMinutes(Int64)
Returns a
Duration that represents the given number of minutes.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromMinutes(long minutes)
Parameters
Type |
Name |
Description |
Int64 |
minutes |
The number of minutes. |
Returns
FromSeconds(Int64)
Returns a
Duration that represents the given number of seconds.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromSeconds(long seconds)
Parameters
Type |
Name |
Description |
Int64 |
seconds |
The number of seconds. |
Returns
FromStandardDays(Int64)
Returns a
Duration that represents the given number of days, assuming a 'standard' 24-hour
day.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromStandardDays(long days)
Parameters
Type |
Name |
Description |
Int64 |
days |
The number of days. |
Returns
FromStandardWeeks(Int64)
Returns a
Duration that represents the given number of weeks, assuming a 'standard' week
consisting of seven 24-hour days.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromStandardWeeks(long weeks)
Parameters
Type |
Name |
Description |
Int64 |
weeks |
The number of weeks. |
Returns
FromTicks(Int64)
Returns a
Duration that represents the given number of ticks.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromTicks(long ticks)
Parameters
Type |
Name |
Description |
Int64 |
ticks |
The number of ticks. |
Returns
FromTimeSpan(TimeSpan)
Returns a
Duration that represents the same number of ticks as the
given
System.TimeSpan.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration FromTimeSpan(TimeSpan timeSpan)
Parameters
Type |
Name |
Description |
TimeSpan |
timeSpan |
The TimeSpan value to convert |
Returns
Type |
Description |
Duration |
A new Duration with the same number of ticks as the given TimeSpan. |
GetHashCode()
Returns a hash code for this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type |
Description |
Int32 |
A hash code for this instance, suitable for use in hashing algorithms and data
structures like a hash table.
|
Overrides
System.ValueType.GetHashCode()
Minus(Duration)
Returns the result of subtracting another duration from this one, for a fluent alternative to operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Duration Minus(Duration other)
Parameters
Type |
Name |
Description |
Duration |
other |
The duration to subtract |
Returns
Type |
Description |
Duration |
A new Duration representing the result of the subtraction. |
Multiply(Duration, Int64)
Multiplies a duration by a number. Friendly alternative to operator*()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Multiply(Duration left, long right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Int64 |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the product of the given values. |
Multiply(Int64, Duration)
Multiplies a duration by a number. Friendly alternative to operator*()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Multiply(long left, Duration right)
Parameters
Type |
Name |
Description |
Int64 |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the product of the given values. |
Negate(Duration)
Implements a friendly alternative to the unary negation operator.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Negate(Duration duration)
Parameters
Type |
Name |
Description |
Duration |
duration |
Duration to negate |
Returns
Type |
Description |
Duration |
The negative value of this duration |
Plus(Duration)
Returns the result of adding another duration to this one, for a fluent alternative to operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Duration Plus(Duration other)
Parameters
Type |
Name |
Description |
Duration |
other |
The duration to add |
Returns
Type |
Description |
Duration |
A new Duration representing the result of the addition. |
Subtract(Duration, Duration)
Subtracts one duration from another. Friendly alternative to operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration Subtract(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the difference of the given values. |
ToString()
Returns a System.String that represents this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override string ToString()
Returns
Type |
Description |
String |
A System.String that represents this instance.
|
Overrides
System.ValueType.ToString()
Formats the value of the current instance using the specified format.
Since 1.2.x
Availability net35-Client, PCL
Declaration
public string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type |
Name |
Description |
String |
patternText |
The System.String specifying the pattern to use.
-or-
null to use the default pattern defined for the type of the System.IFormattable implementation.
|
IFormatProvider |
formatProvider |
The System.IFormatProvider to use to format the value.
-or-
null to obtain the numeric format information from the current locale setting of the operating system.
|
Returns
Type |
Description |
String |
A System.String containing the value of the current instance in the specified format.
|
ToTimeSpan()
Returns a
System.TimeSpan that represents the same number of ticks as this
Duration.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public TimeSpan ToTimeSpan()
Returns
Type |
Description |
TimeSpan |
A new TimeSpan with the same number of ticks as this Duration. |
Operators
Addition(Duration, Duration)
Implements the operator + (addition).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator +(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the sum of the given values. |
Division(Duration, Int64)
Implements the operator / (division).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator /(Duration left, long right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Int64 |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the result of dividing left by
right . |
Equality(Duration, Duration)
Implements the operator == (equality).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator ==(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if values are equal to each other, otherwise false . |
GreaterThan(Duration, Duration)
Implements the operator > (greater than).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator>(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if the left value is greater than the right value, otherwise false . |
GreaterThanOrEqual(Duration, Duration)
Implements the operator >= (greater than or equal).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator >=(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if the left value is greater than or equal to the right value, otherwise false . |
Inequality(Duration, Duration)
Implements the operator != (inequality).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator !=(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if values are not equal to each other, otherwise false . |
LessThan(Duration, Duration)
Implements the operator < (less than).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if the left value is less than the right value, otherwise false . |
LessThanOrEqual(Duration, Duration)
Implements the operator <= (less than or equal).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <=(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if the left value is less than or equal to the right value, otherwise false . |
Multiply(Duration, Int64)
Implements the operator * (multiplication).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator *(Duration left, long right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Int64 |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the result of multiplying left by
right . |
Multiply(Int64, Duration)
Implements the operator * (multiplication).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator *(long left, Duration right)
Parameters
Type |
Name |
Description |
Int64 |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the result of multiplying left by
right . |
Subtraction(Duration, Duration)
Implements the operator - (subtraction).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator -(Duration left, Duration right)
Parameters
Type |
Name |
Description |
Duration |
left |
The left hand side of the operator. |
Duration |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Duration |
A new Duration representing the difference of the given values. |
UnaryNegation(Duration)
Implements the unary negation operator.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Duration operator -(Duration duration)
Parameters
Type |
Name |
Description |
Duration |
duration |
Duration to negate |
Returns
Type |
Description |
Duration |
The negative value of this duration |
Explicit Interface Implementations
IComparable.CompareTo(Object)
Implementation of System.IComparable.CompareTo(System.Object) to compare two offsets.
Since 1.0.x
Availability net35-Client, PCL
Declaration
int IComparable.CompareTo(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The object to compare this value with. |
Returns
Type |
Description |
Int32 |
The result of comparing this instant with another one; see CompareTo(Duration) for general details.
If obj is null, this method returns a value greater than 0.
|
Exceptions
Type |
Condition |
ArgumentException |
obj is non-null but does not refer to an instance of Duration. |
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Implementation of System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext).
Since 1.2.x
Availability net35-Client
Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type |
Name |
Description |
SerializationInfo |
info |
The System.Runtime.Serialization.SerializationInfo to populate with data. |
StreamingContext |
context |
The destination for this serialization. |
IXmlSerializable.GetSchema()
Since 1.2.x
Availability net35-Client, PCL
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type |
Description |
XmlSchema |
|
IXmlSerializable.ReadXml(XmlReader)
Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type |
Name |
Description |
XmlReader |
reader |
|
IXmlSerializable.WriteXml(XmlWriter)
Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type |
Name |
Description |
XmlWriter |
writer |
|
Implements
System.IEquatable<T>
System.IComparable<T>
System.IComparable
System.Xml.Serialization.IXmlSerializable
System.IFormattable
System.Runtime.Serialization.ISerializable