Noda Time
Show / Hide Table of Contents

Struct Duration64

Represents a fixed (and calendar-independent) length of time. This type is a equivalent to Duration, but with a more limited range (a few hundred years) and more compact, high performance representation. It is expected to be used in conjunction with Instant64, typically in scenarios where performance and/or memory usage are important. Note that in most cases, Duration is more appropriate and convenient (with more supported methods etc). This should effectively be regarded as a specialist type for unusually performance-sensitive scenarios.
Since 3.3.x
Availability net8.0, netstandard2.0
Implements
IEquatable<Duration64>
IComparable<Duration64>
IComparable
IFormattable
IAdditionOperators<Duration64, Duration64, Duration64>
ISubtractionOperators<Duration64, Duration64, Duration64>
IUnaryNegationOperators<Duration64, Duration64>
IUnaryPlusOperators<Duration64, Duration64>
IComparisonOperators<Duration64, Duration64, bool>
IEqualityOperators<Duration64, Duration64, bool>
IMinMaxValue<Duration64>
IAdditiveIdentity<Duration64, Duration64>
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: NodaTime.HighPerformance
Assembly: NodaTime.dll
Syntax
public readonly struct Duration64 : IEquatable<Duration64>, IComparable<Duration64>, IComparable, IFormattable, IAdditionOperators<Duration64, Duration64, Duration64>, ISubtractionOperators<Duration64, Duration64, Duration64>, IUnaryNegationOperators<Duration64, Duration64>, IUnaryPlusOperators<Duration64, Duration64>, IComparisonOperators<Duration64, Duration64, bool>, IEqualityOperators<Duration64, Duration64, bool>, IMinMaxValue<Duration64>, IAdditiveIdentity<Duration64, Duration64>
Remarks

A duration is a length of time defined by an integral number of nanoseconds. Although durations are usually used with a positive number of nanoseconds, negative durations are valid, and may occur naturally when e.g. subtracting a later Instant64 from an earlier one.

Equality and ordering are defined in the natural way, simply comparing the number of nanoseconds contained.

The default value of this type is Zero.

Properties

AdditiveIdentity

Gets the additive identity.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 AdditiveIdentity { get; }
Property Value
Type Description
Duration64

Epsilon

Gets a Duration64 value equal to 1 nanosecond; the smallest amount by which an instant can vary.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Epsilon { get; }
Property Value
Type Description
Duration64 A duration representing 1 nanosecond.

MaxValue

Gets the maximum value supported by Duration64. This is around 292 years.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 MaxValue { get; }
Property Value
Type Description
Duration64

MinValue

Gets the minimum (largest negative) value supported by Duration64. This is around -292 years.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 MinValue { get; }
Property Value
Type Description
Duration64

TotalNanoseconds

Gets the total number of nanoseconds in this duration, as an long.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public long TotalNanoseconds { get; }
Property Value
Type Description
long

Zero

Gets a zero Duration64 of 0 nanoseconds.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Zero { get; }
Property Value
Type Description
Duration64 The zero Duration64 value.

Methods

Add(Duration64, Duration64)

Adds one duration to another. Friendly alternative to operator+().
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Add(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
Duration64 A new Duration64 representing the sum of the given values.

CompareTo(Duration64)

Implementation of CompareTo(T) to compare two durations. See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public int CompareTo(Duration64 other)
Parameters
Type Name Description
Duration64 other An object to compare with this object.
Returns
Type Description
int A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
ValueMeaning
< 0This object is less than the other parameter.
0This object is equal to other.
> 0This object is greater than other.

Equals(Duration64)

Indicates whether the current object is equal to another object of the same type. See the type documentation for a description of equality semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public bool Equals(Duration64 other)
Parameters
Type Name Description
Duration64 other An object to compare with this object.
Returns
Type Description
bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to this instance. See the type documentation for a description of equality semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
object obj The object to compare with this instance.
Returns
Type Description
bool true if the specified object is equal to this instance; otherwise, false.
Overrides
ValueType.Equals(object)

FromDays(int)

Returns a Duration64 that represents the given number of days, assuming a 'standard' 24-hour day.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromDays(int days)
Parameters
Type Name Description
int days The number of days.
Returns
Type Description
Duration64 A Duration64 representing the given number of days.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromDuration(Duration)

Creates a Duration64 value representing the same number of nanoseconds as the specified Duration. When this succeeds, this conversion loses no information. If the specified value is outside the range of Duration64, this method will fail with an OverflowException.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromDuration(Duration duration)
Parameters
Type Name Description
Duration duration The value to convert to a Duration64.
Returns
Type Description
Duration64 A Duration64 value equivalent to duration.
Exceptions
Type Condition
OverflowException duration has a value outside the range of Duration64.

FromHours(int)

Returns a Duration64 that represents the given number of hours.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromHours(int hours)
Parameters
Type Name Description
int hours The number of hours.
Returns
Type Description
Duration64 A Duration64 representing the given number of hours.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromMilliseconds(long)

Returns a Duration64 that represents the given number of milliseconds.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromMilliseconds(long milliseconds)
Parameters
Type Name Description
long milliseconds The number of milliseconds.
Returns
Type Description
Duration64 A Duration64 representing the given number of milliseconds.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromMinutes(long)

Returns a Duration64 that represents the given number of minutes.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromMinutes(long minutes)
Parameters
Type Name Description
long minutes The number of minutes.
Returns
Type Description
Duration64 A Duration64 representing the given number of minutes.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromNanoseconds(long)

Returns a Duration64 that represents the given number of nanoseconds.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromNanoseconds(long nanoseconds)
Parameters
Type Name Description
long nanoseconds The number of nanoseconds.
Returns
Type Description
Duration64 A Duration64 representing the given number of nanoseconds.

FromSeconds(long)

Returns a Duration64 that represents the given number of seconds.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromSeconds(long seconds)
Parameters
Type Name Description
long seconds The number of seconds.
Returns
Type Description
Duration64 A Duration64 representing the given number of seconds.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromTicks(long)

Returns a Duration64 that represents the given number of ticks.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromTicks(long ticks)
Parameters
Type Name Description
long ticks The number of ticks.
Returns
Type Description
Duration64 A Duration64 representing the given number of ticks.
Exceptions
Type Condition
OverflowException The specified value cannot be represented as a Duration64.

FromTimeSpan(TimeSpan)

Returns a Duration64 that represents the same number of ticks as the given TimeSpan.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 FromTimeSpan(TimeSpan timeSpan)
Parameters
Type Name Description
TimeSpan timeSpan The TimeSpan value to convert
Returns
Type Description
Duration64 A new Duration64 with the same number of ticks as the given TimeSpan.

GetHashCode()

Returns a hash code for this instance. See the type documentation for a description of equality semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type Description
int A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Overrides
ValueType.GetHashCode()

Max(Duration64, Duration64)

Returns the larger duration of the given two.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Max(Duration64 x, Duration64 y)
Parameters
Type Name Description
Duration64 x The first duration to compare.
Duration64 y The second duration to compare.
Returns
Type Description
Duration64 The larger duration of x or y.
Remarks
A "larger" duration is one that advances time by more than a "smaller" one. This means that a positive duration is always larger than a negative one, for example. (This is the same comparison used by the binary comparison operators.)

Min(Duration64, Duration64)

Returns the smaller duration of the given two.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Min(Duration64 x, Duration64 y)
Parameters
Type Name Description
Duration64 x The first duration to compare.
Duration64 y The second duration to compare.
Returns
Type Description
Duration64 The smaller duration of x or y.
Remarks
A "larger" duration is one that advances time by more than a "smaller" one. This means that a positive duration is always larger than a negative one, for example. (This is the same comparison used by the binary comparison operators.)

Minus(Duration64)

Returns the result of subtracting another duration from this one, for a fluent alternative to operator-().
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public Duration64 Minus(Duration64 other)
Parameters
Type Name Description
Duration64 other The duration to subtract
Returns
Type Description
Duration64 A new Duration64 representing the result of the subtraction.

Negate(Duration64)

Implements a friendly alternative to the unary negation operator.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Negate(Duration64 duration)
Parameters
Type Name Description
Duration64 duration Duration64 to negate
Returns
Type Description
Duration64 The negative value of this duration
Exceptions
Type Condition
OverflowException duration is equal to MinValue.

Plus(Duration64)

Returns the result of adding another duration to this one, for a fluent alternative to operator+().
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public Duration64 Plus(Duration64 other)
Parameters
Type Name Description
Duration64 other The duration to add
Returns
Type Description
Duration64 A new Duration64 representing the result of the addition.

Subtract(Duration64, Duration64)

Subtracts one duration from another. Friendly alternative to operator-().
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 Subtract(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
Duration64 A new Duration64 representing the difference of the given values.

ToDuration()

Converts this value to a Duration representing the same number of nanoseconds. This operation always succeeds and loses no information.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public Duration ToDuration()
Returns
Type Description
Duration A Duration representing the same number of nanoseconds as this one.

ToString()

Returns a string that represents this instance.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public override string ToString()
Returns
Type Description
string The value of the current instance, converted to a Duration, in the default format pattern ("o"), using the current thread's culture to obtain a format provider.
Overrides
ValueType.ToString()

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified pattern.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public string ToString(string? patternText, IFormatProvider? formatProvider)
Parameters
Type Name Description
string patternText The string specifying the pattern to use, or null to use the default format pattern ("o").
IFormatProvider formatProvider The IFormatProvider to use when formatting the value, or null to use the current thread's culture to obtain a format provider.
Returns
Type Description
string A string containing the value of the current instance, converted to a Duration in the specified format.

ToTimeSpan()

Returns a TimeSpan that represents the same number of ticks as this Duration64.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public TimeSpan ToTimeSpan()
Returns
Type Description
TimeSpan A new TimeSpan with the same number of ticks as this Duration.
Remarks
If the number of nanoseconds in a duration is not a whole number of ticks, it is truncated towards zero. For example, durations in the range [-99ns, 99ns] would all count as 0 ticks.

Operators

operator +(Duration64, Duration64)

Implements the operator + (addition).
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 operator +(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
Duration64 A new Duration64 representing the sum of the given values.

operator ==(Duration64, Duration64)

Implements the operator == (equality). See the type documentation for a description of equality semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator ==(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if values are equal to each other, otherwise false.

operator >(Duration64, Duration64)

Implements the operator > (greater than). See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator >(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if the left value is greater than the right value, otherwise false.

operator >=(Duration64, Duration64)

Implements the operator >= (greater than or equal). See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator >=(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if the left value is greater than or equal to the right value, otherwise false.

operator !=(Duration64, Duration64)

Implements the operator != (inequality). See the type documentation for a description of equality semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator !=(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if values are not equal to each other, otherwise false.

operator <(Duration64, Duration64)

Implements the operator < (less than). See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator <(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if the left value is less than the right value, otherwise false.

operator <=(Duration64, Duration64)

Implements the operator <= (less than or equal). See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static bool operator <=(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
bool true if the left value is less than or equal to the right value, otherwise false.

operator -(Duration64, Duration64)

Implements the operator - (subtraction).
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 operator -(Duration64 left, Duration64 right)
Parameters
Type Name Description
Duration64 left The left hand side of the operator.
Duration64 right The right hand side of the operator.
Returns
Type Description
Duration64 A new Duration64 representing the difference of the given values.

operator -(Duration64)

Implements the unary negation operator.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 operator -(Duration64 duration)
Parameters
Type Name Description
Duration64 duration Duration64 to negate
Returns
Type Description
Duration64 The negative value of this duration
Exceptions
Type Condition
OverflowException duration is equal to MinValue.

operator +(Duration64)

Implements the operator + (unary).
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
public static Duration64 operator +(Duration64 duration)
Parameters
Type Name Description
Duration64 duration The duration.
Returns
Type Description
Duration64 The same duration Duration64 as provided.

Explicit Interface Implementations

IComparable.CompareTo(object?)

Implementation of CompareTo(object) to compare two durations. See the type documentation for a description of ordering semantics.
Since 3.3.x
Availability net8.0, netstandard2.0
Declaration
int IComparable.CompareTo(object? obj)
Parameters
Type Name Description
object obj The object to compare this value with.
Returns
Type Description
int The result of comparing this instant with another one; see CompareTo(Duration64) for general details. If obj is null, this method returns a value greater than 0.
Remarks
This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.
Exceptions
Type Condition
ArgumentException obj is non-null but does not refer to an instance of Duration64.

Implements

IEquatable<T>
IComparable<T>
IComparable
IFormattable
IAdditionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
IUnaryNegationOperators<TSelf, TResult>
IUnaryPlusOperators<TSelf, TResult>
IComparisonOperators<TSelf, TOther, TResult>
IEqualityOperators<TSelf, TOther, TResult>
IMinMaxValue<TSelf>
IAdditiveIdentity<TSelf, TResult>
In this article
Back to top Generated by DocFX