Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class NodaTime.​DateInterval

Assembly: NodaTime

Inheritance: object → DateInterval

Implemented Interfaces

An interval between two dates.

Remarks

<para> Equality is defined in a component-wise fashion: two date intervals are considered equal if their start dates are equal to each other and their end dates are equal to each other. Ordering between date intervals is not defined. </para> <para> The two dates must be in the same calendar, and the end date must not be earlier than the start date. </para> <para> 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. </para>

Properties

public LocalDate
Start
Gets the start date of the interval.
public LocalDate
End
Gets the end date of the interval.
public int
Length
Gets the length of this date interval in days. This will always be at least 1.
Calendar
Gets the calendar system of the dates in this interval.

Methods

public int
GetHashCode​()
Returns the hash code for this interval, consistent with <see cref="M:NodaTime.DateInterval.Equals(NodaTime.DateInterval)" /> . See the type documentation for a description of equality semantics.
Returns The hash code for this interval.
public bool
Equals​(DateInterval other)
Compares the given date interval for equality with this one. See the type documentation for a description of equality semantics.
Returns True if this date interval has the same same start and end date as the one specified.
other The date interval to compare this one with.
public bool
Equals​(object obj)
Compares the given object for equality with this one, as per <see cref="M:NodaTime.DateInterval.Equals(NodaTime.DateInterval)" /> . See the type documentation for a description of equality semantics.
Returns true if the other object is a date interval equal to this one, consistent with <see cref="M:NodaTime.DateInterval.Equals(NodaTime.DateInterval)" /> .
obj The value to compare this one with.
public bool
Contains​(LocalDate date)
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.
Returns <c>true</c> if <paramref name="date" /> is within this interval; <c>false</c> otherwise.
date The date to check for containment within this interval.
public bool
Contains​(DateInterval interval)
Checks whether the given interval is within this interval. This requires that the start date of the specified interval is not earlier than the start date of this interval, and the end date of the specified interval is not later than the end date of this interval.
Returns <c>true</c> if <paramref name="interval" /> is within this interval; <c>false</c> otherwise.
interval The interval to check for containment within this interval.
Remarks An interval contains another interval with same start and end dates, or itself.
public string
ToString​()
Returns a string representation of this interval.
Returns A string representation of this interval, as <c>[start, end]</c> , where "start" and "end" are the dates formatted using an ISO-8601 compatible pattern.
public void
Deconstruct​(LocalDate& start, LocalDate& end)
public DateInterval
Intersection​(DateInterval interval)
Returns the intersection between the given interval and this interval.
Returns A <see cref="T:NodaTime.DateInterval" /> corresponding to the intersection between the given interval and the current instance. If there is no intersection, a null reference is returned.
interval The specified interval to intersect with this one.
public DateInterval
Union​(DateInterval interval)
Returns the union between the given interval and this interval, as long as they're overlapping or contiguous.
Returns A <see cref="T:NodaTime.DateInterval" /> corresponding to the union between the given interval and the current instance, in the case the intervals overlap or are contiguous; a null reference otherwise.
interval The specified interval from which to generate the union interval.
GetEnumerator​()
Returns an enumerator for the dates in the interval, including both <see cref="P:NodaTime.DateInterval.Start" /> and <see cref="P:NodaTime.DateInterval.End" /> .
Returns An enumerator for the interval.
protected void
Finalize​()
Inherited from object
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object