Table of Contents

INotableDateProvider Interface

Definition

Namespace
Bodu.Globalization.Calendar
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.3.0
Source
INotableDateProvider.cs

Contributes fully-formed notable-date occurrences to a NotableDateService in code, for sources that cannot be expressed as authored resource rules.

public interface INotableDateProvider
Extension Methods

Examples

// Contribute a company founding anniversary that is not expressible as an authored rule.
public sealed class FoundingDayProvider : INotableDateProvider
{
    public IEnumerable<NotableDate> GetNotableDates(DateRange range, string territory)
    {
        for (int year = range.StartDate.Year; year <= range.EndDate.Year; year++)
        {
            DateOnly date = new(year, 6, 15);
            yield return new NotableDate(
                Date: date,
                ActualDate: date,
                IsObserved: false,
                Identity: new NotableDateRuleIdentity("company", "company-founding", "fixed"),
                DisplayName: "Company Founding Day",
                TerritoryCode: territory,
                Category: NotableDateCategory.Observance,
                Priority: 0,
                DurationDays: 1,
                IsNonWorkingDay: false,
                Tags: Array.Empty<string>(),
                AdjustmentPolicyId: null,
                AdjustmentReason: null);
        }
    }
}

// Register the provider through the service options.
NotableDateService service = new(resource, new NotableDateServiceOptions
{
    Providers = new[] { new FoundingDayProvider() },
});

Remarks

A provider returns finished NotableDate occurrences - date and all metadata - for a requested window and territory, complementing the resource-authored rules. It is the code-first counterpart to authoring a rule, and is registered with the service through Providers.

Provider occurrences are terminal: the service emits them as supplied (after intersecting them with the requested range and applying any query filter), so they do not pass through adjustment policies, declarative overrides, territory specificity, or the occupied-day interaction that resource rules participate in. They do take part in the final date ordering and the resource's same-day collision policy alongside resource occurrences. A provider that needs observed-date shifting must compute it itself.

Under a same-day collision policy other than KeepAll, the service asks for a range that starts before the queried window, early enough to hold every day an occurrence reaching into the window can be emitted on, so that a provider occurrence on such a day takes part in that day's collision even when its own span ends before the window. When a provider occurrence reaching into the window is longer than any the range allowed for, the service asks again from an earlier start. Occurrences that do not reach into the window take part only in collisions and are not returned.

Methods

GetNotableDates(DateRange, string)

Produces the notable-date occurrences that fall within the requested range for the territory.

IEnumerable<NotableDate> GetNotableDates(DateRange range, string territory)

Parameters

range DateRange

The inclusive range being resolved.

territory string

The requested territory code.

Returns

IEnumerable<NotableDate>

The occurrences the provider contributes; an empty sequence when it has none. Occurrences whose span does not intersect range are ignored by the service.

Applies to

ProductVersions
.NET8, 10

See Also