DateRange Struct
Definition
- Namespace
- Bodu.Globalization.Calendar
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
- Source
- DateRange.cs
Represents an inclusive range of calendar days bounded by a start and end date.
public readonly struct DateRange : IEquatable<DateRange>
- Implements
- Inherited Members
- Extension Methods
Examples
// The whole of 2026, passed to a service query.
DateRange year = new(new DateOnly(2026, 1, 1), new DateOnly(2026, 12, 31));
int days = year.DayCount; // 365
bool inRange = year.Contains(new DateOnly(2026, 7, 4)); // true
IReadOnlyList<NotableDate> occurrences = service.Resolve(year, "US");
Remarks
Both endpoints are inclusive, so a range whose start equals its end spans a single day and reports a DayCount of one. The struct does not enforce ordering at construction; IsValid reports whether the start is on or before the end, and the containment and overlap members return false for an ill-formed range rather than throwing.
Constructors
DateRange(DateOnly, DateOnly)
Represents an inclusive range of calendar days bounded by a start and end date.
public DateRange(DateOnly StartDate, DateOnly EndDate)
Parameters
StartDateDateOnlyThe first day of the range, inclusive.
EndDateDateOnlyThe last day of the range, inclusive.
Examples
// The whole of 2026, passed to a service query.
DateRange year = new(new DateOnly(2026, 1, 1), new DateOnly(2026, 12, 31));
int days = year.DayCount; // 365
bool inRange = year.Contains(new DateOnly(2026, 7, 4)); // true
IReadOnlyList<NotableDate> occurrences = service.Resolve(year, "US");
Remarks
Both endpoints are inclusive, so a range whose start equals its end spans a single day and reports a DayCount of one. The struct does not enforce ordering at construction; IsValid reports whether the start is on or before the end, and the containment and overlap members return false for an ill-formed range rather than throwing.
- See Also
Properties
DayCount
Gets the number of days the range spans, inclusive of both endpoints.
public int DayCount { get; }
Property Value
- int
The inclusive day count, or zero when the range is not well-formed.
EndDate
The last day of the range, inclusive.
public DateOnly EndDate { get; init; }
Property Value
IsValid
Gets a value indicating whether the range is well-formed, with a start no later than its end.
public bool IsValid { get; }
Property Value
StartDate
The first day of the range, inclusive.
public DateOnly StartDate { get; init; }
Property Value
Methods
Contains(DateRange)
Determines whether the range fully contains the supplied range.
public bool Contains(DateRange other)
Parameters
otherDateRangeThe range to test for containment.
Returns
Contains(DateOnly)
Determines whether the range contains the supplied date.
public bool Contains(DateOnly date)
Parameters
dateDateOnlyThe date to test.
Returns
Deconstruct(out DateOnly, out DateOnly)
public void Deconstruct(out DateOnly StartDate, out DateOnly EndDate)
Parameters
Equals(DateRange)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DateRange other)
Parameters
otherDateRangeAn object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Intersects(DateRange)
Determines whether the range shares at least one day with the supplied range.
public bool Intersects(DateRange other)
Parameters
otherDateRangeThe range to test for overlap.
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator ==(DateRange, DateRange)
public static bool operator ==(DateRange left, DateRange right)
Parameters
Returns
operator !=(DateRange, DateRange)
public static bool operator !=(DateRange left, DateRange right)
Parameters
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |