Table of Contents

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

StartDate DateOnly

The first day of the range, inclusive.

EndDate DateOnly

The 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

DateOnly

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

bool

true when the start is on or before the end; otherwise false.

StartDate

The first day of the range, inclusive.

public DateOnly StartDate { get; init; }

Property Value

DateOnly

Methods

Contains(DateRange)

Determines whether the range fully contains the supplied range.

public bool Contains(DateRange other)

Parameters

other DateRange

The range to test for containment.

Returns

bool

true when both ranges are well-formed and every day of other falls within this range; otherwise false.

Contains(DateOnly)

Determines whether the range contains the supplied date.

public bool Contains(DateOnly date)

Parameters

date DateOnly

The date to test.

Returns

bool

true if the date falls within the range; otherwise false.

Deconstruct(out DateOnly, out DateOnly)

public void Deconstruct(out DateOnly StartDate, out DateOnly EndDate)

Parameters

StartDate DateOnly
EndDate DateOnly

Equals(DateRange)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(DateRange other)

Parameters

other DateRange

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

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

other DateRange

The range to test for overlap.

Returns

bool

true when both ranges are well-formed and overlap on at least one day; otherwise false.

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

left DateRange
right DateRange

Returns

bool

operator !=(DateRange, DateRange)

public static bool operator !=(DateRange left, DateRange right)

Parameters

left DateRange
right DateRange

Returns

bool

Applies to

ProductVersions
.NET8, 10

See Also