Struct Interval
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public readonly struct Interval : IEquatable<Interval>, IXmlSerializable
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Constructors
Interval(Instant, Instant)
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.
Declaration
public Interval(Instant start, Instant end)
Parameters
Type | Name | Description |
---|---|---|
Instant | start | The start Instant. |
Instant | end | The end Instant. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Sample snippet
using NodaTime;
using System;
Instant start = Instant.FromUtc(2019, 1, 1, 15, 25, 48);
Instant end = Instant.FromUtc(2019, 1, 1, 16, 25, 48);
Interval interval = new Interval(start, end);
Console.WriteLine(interval.Start);
Console.WriteLine(interval.End);
Output:
2019-01-01T15:25:48Z
2019-01-01T16:25:48Z
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | end is earlier than start . |
Interval(Instant?, Instant?)
Declaration
public Interval(Instant? start, Instant? end)
Parameters
Type | Name | Description |
---|---|---|
Instant? | start | The start Instant or null. |
Instant? | end | The end Instant or null. |
Remarks
Sample snippet
using NodaTime;
using System;
Instant end = Instant.FromUtc(2019, 1, 1, 16, 25, 48);
Interval interval = new Interval(null, end);
Console.WriteLine(interval.HasStart);
Console.WriteLine(interval.HasEnd);
Console.WriteLine(interval.End);
Output:
False
True
2019-01-01T16:25:48Z
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | end is earlier than start ,
if they are both non-null. |
Properties
Duration
Declaration
public Duration Duration { get; }
Property Value
Type | Description |
---|---|
Duration | The duration of the interval. |
Remarks
Sample snippet
using NodaTime;
using System;
Instant start = Instant.FromUtc(2019, 1, 1, 3, 10, 20);
Instant end = Instant.FromUtc(2019, 1, 1, 9, 10, 20);
Interval interval = new Interval(start, end);
var duration = interval.Duration;
Console.WriteLine(duration);
Output:
0:06:00:00
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The interval extends to the start or end of time. |
End
Declaration
public Instant End { get; }
Property Value
Type | Description |
---|---|
Instant | The end Instant. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The interval extends to the end of time. |
See Also
HasEnd
true
if this interval has a fixed end point, or false
if it
extends to the end of time.
Declaration
public bool HasEnd { get; }
Property Value
Type | Description |
---|---|
bool | true if this interval has a fixed end point, or false if it
extends to the end of time. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
HasStart
true
if this interval has a fixed start point, or false
if it
extends to the start of time.
Declaration
public bool HasStart { get; }
Property Value
Type | Description |
---|---|
bool | true if this interval has a fixed start point, or false if it
extends to the start of time. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Start
Declaration
public Instant Start { get; }
Property Value
Type | Description |
---|---|
Instant | The start Instant. |
Remarks
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The interval extends to the start of time. |
See Also
Methods
AddSchema(XmlSchemaSet)
xmlSchemaSet
.
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type | Name | Description |
---|---|---|
XmlSchemaSet | xmlSchemaSet | The XML schema set provided by XmlSchemaExporter. |
Returns
Type | Description |
---|---|
XmlQualifiedName | The qualified name of the schema type that was added to the xmlSchemaSet . |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Contains(Instant)
Declaration
public bool Contains(Instant instant)
Parameters
Type | Name | Description |
---|---|---|
Instant | instant | Instant to test. |
Returns
Type | Description |
---|---|
bool | True if this interval contains the given instant; false otherwise. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Sample snippet
using NodaTime;
using System;
Instant start = Instant.FromUtc(2019, 1, 1, 15, 25, 48);
Instant end = Instant.FromUtc(2019, 1, 1, 16, 25, 48);
Interval interval = new Interval(start, end);
Console.WriteLine(interval.Contains(Instant.FromUtc(2019, 1, 1, 15, 50, 50)));
Output:
True
Deconstruct(out Instant?, out Instant?)
Declaration
public void Deconstruct(out Instant? start, out Instant? end)
Parameters
Type | Name | Description |
---|---|---|
Instant? | start | The start of the interval. |
Instant? | end | The end of the interval. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Sample snippet
using NodaTime;
using System;
Instant? start = Instant.FromUtc(2019, 1, 2, 3, 10, 11);
Instant? end = Instant.FromUtc(2020, 4, 5, 6, 12, 13);
Interval interval = new Interval(start, end);
interval.Deconstruct(out start, out end);
Console.WriteLine(start);
Console.WriteLine(end);
Output:
2019-01-02T03:10:11Z
2020-04-05T06:12:13Z
Equals(Interval)
Declaration
public bool Equals(Interval other)
Parameters
Type | Name | Description |
---|---|---|
Interval | other | The value to compare with this instance. |
Returns
Type | Description |
---|---|
bool |
true if the value of this instant is equal to the value of the other parameter;
otherwise, false.
|
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Equals(object?)
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
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of this interval. |
Overrides
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
Sample snippet
using NodaTime;
using System;
Instant start = Instant.FromUtc(2019, 1, 2, 10, 11, 12);
Instant end = Instant.FromUtc(2020, 2, 3, 12, 13, 14);
Interval interval = new Interval(start, end);
var stringRepresentation = interval.ToString();
Console.WriteLine(stringRepresentation);
Output:
2019-01-02T10:11:12Z/2020-02-03T12:13:14Z
Operators
operator ==(Interval, Interval)
Declaration
public static bool operator ==(Interval left, Interval right)
Parameters
Type | Name | Description |
---|---|---|
Interval | left | The left. |
Interval | right | The right. |
Returns
Type | Description |
---|---|
bool | The result of the operator. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.
operator !=(Interval, Interval)
Declaration
public static bool operator !=(Interval left, Interval right)
Parameters
Type | Name | Description |
---|---|---|
Interval | left | The left. |
Interval | right | The right. |
Returns
Type | Description |
---|---|
bool | The result of the operator. |
Remarks
Equality is defined in a component-wise fashion: two intervals are considered equal if their start instants are equal to each other and their end instants are equal to each other. Ordering between intervals is not defined.
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.
The default value of this type is an empty interval with a start and end of UnixEpoch.