Noda Time
Show / Hide Table of Contents

Class DateInterval

An interval between two dates.
Inheritance
Object
DateInterval
Implements
IEquatable<DateInterval>
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public sealed class DateInterval : IEquatable<DateInterval>
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Constructors

DateInterval(LocalDate, LocalDate)

Constructs a date interval from a start date and an end date, both of which are included in the interval.
Declaration
public DateInterval(LocalDate start, LocalDate end)
Parameters
Type Name Description
LocalDate start Start date of the interval
LocalDate end End date of the interval
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Exceptions
Type Condition
ArgumentException end is earlier than start or the two dates are in different calendars.

Properties

End

Gets the end date of the interval.
Declaration
public LocalDate End { get; }
Property Value
Type Description
LocalDate The end date of the interval.
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Length

Gets the length of this date interval in days. This will always be at least 1.
Declaration
public int Length { get; }
Property Value
Type Description
Int32 The length of this date interval in days.
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Start

Gets the start date of the interval.
Declaration
public LocalDate Start { get; }
Property Value
Type Description
LocalDate The start date of the interval.
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Methods

Contains(LocalDate)

Checks whether the given date is within this date interval. This requires that the date is not earlier than the start date, and not later than the end date.
Declaration
public bool Contains(LocalDate date)
Parameters
Type Name Description
LocalDate date The date to check for containment within this interval.
Returns
Type Description
Boolean true if date is within this interval; false otherwise.
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Exceptions
Type Condition
ArgumentException date is not in the same calendar as the start and end date of this interval.

Equals(DateInterval)

Compares the given date interval for equality with this one.
Declaration
public bool Equals(DateInterval other)
Parameters
Type Name Description
DateInterval other The date interval to compare this one with.
Returns
Type Description
Boolean True if this date interval has the same same start and end date as the one specified.
Remarks
Date intervals are equal if they have the same start and end dates.

Equals(Object)

Compares the given object for equality with this one, as per Equals(DateInterval).
Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj The value to compare this one with.
Returns
Type Description
Boolean true if the other object is a date interval equal to this one, consistent with Equals(DateInterval).
Overrides
Object.Equals(Object)
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

GetHashCode()

Returns the hash code for this interval, consistent with Equals(DateInterval).
Declaration
public override int GetHashCode()
Returns
Type Description
Int32 The hash code for this interval.
Overrides
Object.GetHashCode()
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

ToString()

Returns a string representation of this interval.
Declaration
public override string ToString()
Returns
Type Description
String A string representation of this interval, as [start, end], where "start" and "end" are the dates formatted using an ISO-8601 compatible pattern.
Overrides
Object.ToString()
Remarks

The two dates must be in the same calendar, and the end date must not be earlier than the start date.

The end date is deemed to be part of the range, as this matches many real life uses of date ranges. For example, if someone says "I'm going to be on holiday from Monday to Friday," they usually mean that Friday is part of their holiday.

Operators

Equality(DateInterval, DateInterval)

Compares two DateInterval values for equality.
Declaration
public static bool operator ==(DateInterval lhs, DateInterval rhs)
Parameters
Type Name Description
DateInterval lhs The first value to compare
DateInterval rhs The second value to compare
Returns
Type Description
Boolean True if the two date intervals have the same properties; false otherwise.
Remarks
Date intervals are equal if they have the same start and end dates.

Inequality(DateInterval, DateInterval)

Compares two DateInterval values for inequality.
Declaration
public static bool operator !=(DateInterval lhs, DateInterval rhs)
Parameters
Type Name Description
DateInterval lhs The first value to compare
DateInterval rhs The second value to compare
Returns
Type Description
Boolean False if the two date intervals have the same start and end date; true otherwise.
Remarks
Date intervals are equal if they have the same start and end dates.

Implements

System.IEquatable<T>
In This Article
Back to top Generated by DocFX