Table of Contents

NotableDateService Class

Definition

Namespace
Bodu.Globalization.Calendar
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
NotableDateService.cs

Resolves notable-date occurrences from a loaded NotableDateResource for a requested territory and day or date range. This class cannot be inherited.

public sealed class NotableDateService : INotableDateService
Inheritance
NotableDateService
Implements
Inherited Members
Extension Methods

Examples

// Load a document and build a service over it.
NotableDateResource resource = NotableDateResourceLoader.Load(documentXml);
NotableDateService service = new(resource);

// Resolve the occurrences emitted on Christmas Day for Ontario, Canada.
IReadOnlyList<NotableDate> christmas = service.Resolve(new DateOnly(2026, 12, 25), "CA-ON");

Remarks

Resolution runs in two phases. The first phase calculates every actual occurrence purely and seeds an occupied-day set with the actual dates of non-working occurrences. The second phase places observed dates in an explicit precedence order - earliest actual date, then higher priority, then stable identity - so that a substitute that opts in to SkipNonWorkingDates advances past days already claimed by other holidays.

Inclusion is decided by the emitted (observed) date, so a single-day query and a range query covering the same dates return consistent results. To capture occurrences whose actual date lies just outside the requested window but whose observed date falls inside it, the service scans one civil year either side of the window.

Thread safety. The service is immutable once constructed and holds no per-query mutable state, so a single instance is safe to share across threads. Prefer reusing one instance per resource rather than reconstructing it per query, since each query re-scans the resource.

When to use. Construct directly from a NotableDateResource when you load documents yourself with NotableDateResourceLoader; use a data pack's CreateService factory (for example the AmericasCalendarData bundle) for bundled rules; or register the service through the dependency-injection extensions for application hosting. Pass the optional collaborator overloads only when a document references custom algorithms, collision resolvers, or adjustment handlers.

Constructors

NotableDateService(NotableDateResource)

Initializes a new instance of the NotableDateService class over a resource using only built-in behaviour.

public NotableDateService(NotableDateResource resource)

Parameters

resource NotableDateResource

The loaded resource the service draws occurrences from.

Exceptions

ArgumentNullException

resource is null.

NotableDateService(NotableDateResource, NotableDateServiceOptions?)

Initializes a new instance of the NotableDateService class over a resource with the optional collaborators supplied by options.

public NotableDateService(NotableDateResource resource, NotableDateServiceOptions? options)

Parameters

resource NotableDateResource

The loaded resource the service draws occurrences from.

options NotableDateServiceOptions

The optional collaborators consulted when a document references custom algorithms, collision resolution, adjustment handlers, trigger handlers, or code-first providers, or null for built-ins only.

Exceptions

ArgumentNullException

resource is null.

Methods

GetSupportedCalendars()

Gets the distinct calendar systems any rule in the resource is expressed in.

public IReadOnlyList<CalendarSystem> GetSupportedCalendars()

Returns

IReadOnlyList<CalendarSystem>

The calendar systems in use, in ascending order.

GetSupportedTerritories()

Gets the distinct territories any rule in the resource is scoped to.

public IReadOnlyList<string> GetSupportedTerritories()

Returns

IReadOnlyList<string>

The scoped territory codes in case-insensitive ascending order; empty when every rule is global (unscoped).

Resolve(DateRange, string)

Resolves the notable-date occurrences emitted within an inclusive date range for the requested territory.

public IReadOnlyList<NotableDate> Resolve(DateRange range, string territory)

Parameters

range DateRange

The inclusive range of days to resolve.

territory string

The requested territory code.

Returns

IReadOnlyList<NotableDate>

The occurrences whose emitted date falls within the range, ordered by date then identity.

Exceptions

ArgumentNullException

territory is null.

ArgumentOutOfRangeException

The range start is later than its end.

Resolve(DateRange, string, NotableDateFilter)

Resolves the notable-date occurrences emitted within an inclusive date range for the requested territory, restricted to those matching the supplied filter.

public IReadOnlyList<NotableDate> Resolve(DateRange range, string territory, NotableDateFilter filter)

Parameters

range DateRange

The inclusive range of days to resolve.

territory string

The requested territory code.

filter NotableDateFilter

The filter that emitted occurrences must satisfy.

Returns

IReadOnlyList<NotableDate>

The matching occurrences, ordered by date then identity.

Exceptions

ArgumentNullException

territory or filter is null.

ArgumentOutOfRangeException

The range start is later than its end.

Resolve(DateOnly, string)

Resolves the notable-date occurrences emitted on a single day for the requested territory.

public IReadOnlyList<NotableDate> Resolve(DateOnly date, string territory)

Parameters

date DateOnly

The day to resolve.

territory string

The requested territory code.

Returns

IReadOnlyList<NotableDate>

The occurrences whose emitted date equals date; empty when there are none.

Resolve(DateOnly, string, NotableDateFilter)

Resolves the notable-date occurrences emitted on a single day for the requested territory, restricted to those matching the supplied filter.

public IReadOnlyList<NotableDate> Resolve(DateOnly date, string territory, NotableDateFilter filter)

Parameters

date DateOnly

The day to resolve.

territory string

The requested territory code.

filter NotableDateFilter

The filter that emitted occurrences must satisfy.

Returns

IReadOnlyList<NotableDate>

The matching occurrences; empty when there are none.

Exceptions

ArgumentNullException

territory or filter is null.

Applies to

ProductVersions
.NET8, 10

See Also