Show / Hide Table of Contents

Struct Interval

An interval between two instants in time (start and end).
Since 1.0.x
Availability netstandard2.0
Implements
System.IEquatable<Interval>
System.Xml.Serialization.IXmlSerializable
Inherited Members
System.ValueType.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public struct Interval : IEquatable<Interval>, IXmlSerializable
Remarks

The interval includes the start instant and excludes the end instant. However, an interval may be missing its start or end, in which case the interval is deemed to be infinite in that direction.

The end may equal the start (resulting in an empty interval), but will not be before the start.

Constructors

Interval(Instant, Instant)

Initializes a new instance of the Interval struct. The interval includes the start instant and excludes the end instant. The end may equal the start (resulting in an empty interval), but must not be before the start.
Since 1.0.x
Availability netstandard2.0
Declaration
public Interval(Instant start, Instant end)
Parameters
Type Name Description
Instant start The start Instant.
Instant end The end Instant.
Exceptions
Type Condition
System.ArgumentOutOfRangeException end is earlier than start.

Interval(Nullable<Instant>, Nullable<Instant>)

Initializes a new instance of the Interval struct from two nullable Instant values.
Since 2.0.x
Availability netstandard2.0
Declaration
public Interval(Instant? start, Instant? end)
Parameters
Type Name Description
System.Nullable<Instant> start The start Instant or null.
System.Nullable<Instant> end The end Instant or null.
Remarks
If the start is null, the interval is deemed to stretch to the start of time. If the end is null, the interval is deemed to stretch to the end of time.
Exceptions
Type Condition
System.ArgumentOutOfRangeException end is earlier than start, if they are both non-null.

Properties

Duration

Returns the duration of the interval.
Since 1.0.x
Availability netstandard2.0
Declaration
public Duration Duration { get; }
Property Value
Type Description
Duration The duration of the interval.
Remarks
This will always be a non-negative duration, though it may be zero.
Exceptions
Type Condition
System.InvalidOperationException The interval extends to the start or end of time.

End

Gets the end instant - the exclusive upper bound of the interval.
Since 1.0.x
Availability netstandard2.0
Declaration
public Instant End { get; }
Property Value
Type Description
Instant The end Instant.
Exceptions
Type Condition
System.InvalidOperationException The interval extends to the end of time.
See Also
HasEnd

HasEnd

Returns true if this interval has a fixed end point, or false if it extends to the end of time.
Since 2.0.x
Availability netstandard2.0
Declaration
public bool HasEnd { get; }
Property Value
Type Description
System.Boolean true if this interval has a fixed end point, or false if it extends to the end of time.

HasStart

Returns true if this interval has a fixed start point, or false if it extends to the start of time.
Since 2.0.x
Availability netstandard2.0
Declaration
public bool HasStart { get; }
Property Value
Type Description
System.Boolean true if this interval has a fixed start point, or false if it extends to the start of time.

Start

Gets the start instant - the inclusive lower bound of the interval.
Since 1.0.x
Availability netstandard2.0
Declaration
public Instant Start { get; }
Property Value
Type Description
Instant The start Instant.
Remarks
This will never be later than End, though it may be equal to it.
Exceptions
Type Condition
System.InvalidOperationException The interval extends to the start of time.
See Also
HasStart

Methods

Contains(Instant)

Returns whether or not this interval contains the given instant.
Since 1.2.x
Availability netstandard2.0
Declaration
public bool Contains(Instant instant)
Parameters
Type Name Description
Instant instant Instant to test.
Returns
Type Description
System.Boolean True if this interval contains the given instant; false otherwise.

Deconstruct(out Nullable<Instant>, out Nullable<Instant>)

Deconstruct this value into its components.
Since 2.3.x
Availability netstandard2.0
Declaration
public void Deconstruct(out Instant? start, out Instant? end)
Parameters
Type Name Description
System.Nullable<Instant> start The start of the interval.
System.Nullable<Instant> end The end of the interval.

Equals(Interval)

Indicates whether the value of this interval is equal to the value of the specified interval.
Since 1.0.x
Availability netstandard2.0
Declaration
public bool Equals(Interval other)
Parameters
Type Name Description
Interval other The value to compare with this instance.
Returns
Type Description
System.Boolean true if the value of this instant is equal to the value of the other parameter; otherwise, false.

Equals(Object)

Determines whether the specified System.Object is equal to this instance.
Since 1.0.x
Availability netstandard2.0
Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
System.Object obj The System.Object to compare with this instance.
Returns
Type Description
System.Boolean true if the specified System.Object is equal to this instance; otherwise, false.

GetHashCode()

Returns the hash code for this instance.
Since 1.0.x
Availability netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32 A 32-bit signed integer that is the hash code for this instance.
Overrides
System.ValueType.GetHashCode()

ToString()

Returns a string representation of this interval, in extended ISO-8601 format: the format is "start/end" where each instant uses a format of "uuuu'-'MM'-'dd'T'HH':'mm':'ss;FFFFFFFFF'Z'". If the start or end is infinite, the relevant part uses "StartOfTime" or "EndOfTime" to represent this.
Since 1.0.x
Availability netstandard2.0
Declaration
public override string ToString()
Returns
Type Description
System.String A string representation of this interval.
Overrides
System.ValueType.ToString()

Operators

Equality(Interval, Interval)

Implements the operator ==.
Since 1.0.x
Availability netstandard2.0
Declaration
public static bool operator ==(Interval left, Interval right)
Parameters
Type Name Description
Interval left The left.
Interval right The right.
Returns
Type Description
System.Boolean The result of the operator.

Inequality(Interval, Interval)

Implements the operator !=.
Since 1.0.x
Availability netstandard2.0
Declaration
public static bool operator !=(Interval left, Interval right)
Parameters
Type Name Description
Interval left The left.
Interval right The right.
Returns
Type Description
System.Boolean The result of the operator.

Explicit Interface Implementations

IXmlSerializable.GetSchema()

Since 1.2.x
Availability netstandard2.0
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type Description
System.Xml.Schema.XmlSchema

IXmlSerializable.ReadXml(XmlReader)

Since 1.2.x
Availability netstandard2.0
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type Name Description
System.Xml.XmlReader reader
Exceptions
Type Condition
System.ArgumentNullException reader is null.

IXmlSerializable.WriteXml(XmlWriter)

Since 1.2.x
Availability netstandard2.0
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type Name Description
System.Xml.XmlWriter writer
Exceptions
Type Condition
System.ArgumentNullException writer is null.

Implements

System.IEquatable<T>
System.Xml.Serialization.IXmlSerializable
Back to top