DateRangeCoverage Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.3.0
- Source
- DateRangeCoverage.cs
Tracks the set of DateOnly ranges that have actually been observed, as a sorted list of disjoint inclusive intervals that merge on insertion but never bridge a gap.
public sealed class DateRangeCoverage
- Inheritance
-
DateRangeCoverage
- Inherited Members
- Extension Methods
Remarks
The type answers one question precisely: has every day in a requested window already been seen? Unlike a single
(min, max) envelope, it preserves interior gaps, so a window that straddles an unobserved stretch is
correctly reported as not covered. Two intervals are merged only when they overlap or touch - the later interval
begins on or before the day after the earlier one ends - so a genuine gap of one or more days keeps them separate.
When a window is not covered, TryGetUncoveredSpan(DateOnly, DateOnly, out DateOnly, out DateOnly) reports the span from its first unrecorded day to its last, so a caller can fetch only that span rather than the whole window again.
Instances are not thread-safe; callers that mutate a shared instance must synchronize access themselves.
Constructors
DateRangeCoverage()
public DateRangeCoverage()
Properties
Intervals
Gets the recorded intervals in ascending order.
public IReadOnlyList<(DateOnly Start, DateOnly End)> Intervals { get; }
Property Value
- IReadOnlyList<(DateOnly Start, DateOnly End)>
The disjoint inclusive intervals that make up the coverage, ordered by start date.
IsEmpty
Gets a value indicating whether no range has been recorded.
public bool IsEmpty { get; }
Property Value
Methods
Add(DateOnly, DateOnly)
Records the inclusive range start..end as observed, merging it with any
overlapping or adjacent intervals already present.
public void Add(DateOnly start, DateOnly end)
Parameters
startDateOnlyThe inclusive first date of the observed range.
endDateOnlyThe inclusive last date of the observed range.
Exceptions
- ArgumentOutOfRangeException
Thrown when
startis later thanend.
Contains(DateOnly)
Reports whether the supplied date has been recorded.
public bool Contains(DateOnly date)
Parameters
dateDateOnlyThe date to test.
Returns
Contains(DateOnly, DateOnly)
Reports whether every day in the inclusive range start..end has been
recorded.
public bool Contains(DateOnly start, DateOnly end)
Parameters
startDateOnlyThe inclusive first date of the window to test.
endDateOnlyThe inclusive last date of the window to test.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
startis later thanend.
TryGetUncoveredSpan(DateOnly, DateOnly, out DateOnly, out DateOnly)
Finds the span of a window that is not yet recorded: from its first unrecorded day to its last.
public bool TryGetUncoveredSpan(DateOnly start, DateOnly end, out DateOnly uncoveredStart, out DateOnly uncoveredEnd)
Parameters
startDateOnlyThe inclusive first date of the window to test.
endDateOnlyThe inclusive last date of the window to test.
uncoveredStartDateOnlyWhen this method returns true, the first day of the window that has not been recorded; otherwise default.
uncoveredEndDateOnlyWhen this method returns true, the last day of the window that has not been recorded; otherwise default.
Returns
- bool
true when some day of the window has not been recorded; false when every day has (the window is Contains(DateOnly, DateOnly)).
Remarks
A caller that fetches only the reported span, rather than the whole window, fetches every missing day at the cost of at most the recorded days between the first and last missing ones, in a single request.
Exceptions
- ArgumentOutOfRangeException
Thrown when
startis later thanend.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |