Table of Contents

RuleApplicability Class

Definition

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

Describes where and when a rule applies: its calendar system, optional year bounds, explicit territories, and optional inclusion/exclusion years.

public sealed class RuleApplicability
Inheritance
RuleApplicability
Inherited Members
Extension Methods

Remarks

Territories are explicit codes; there are no comma-delimited strings. A rule with no territories is treated as global and applies to every requested territory. A subnational query (for example AU-NSW) matches a rule scoped to its parent territory (AU), but a national query does not match a subnational-only rule.

Constructors

RuleApplicability(CalendarSystem, int?, int?, IEnumerable<string>, IEnumerable<int>, IEnumerable<int>, int?, int?)

Initializes a new instance of the RuleApplicability class.

public RuleApplicability(CalendarSystem calendar, int? fromYear, int? toYear, IEnumerable<string> territories, IEnumerable<int> onlyYears, IEnumerable<int> exceptYears, int? everyYears = null, int? anchorYear = null)

Parameters

calendar CalendarSystem

The calendar system the rule's strategy is expressed in.

fromYear int?

The first applicable Gregorian year, or null for no lower bound.

toYear int?

The last applicable Gregorian year, or null for no upper bound.

territories IEnumerable<string>

The explicit territories the rule applies to.

onlyYears IEnumerable<int>

The explicit inclusion years, or an empty sequence for no restriction.

exceptYears IEnumerable<int>

The explicit exclusion years, or an empty sequence for no exclusions.

everyYears int?

The recurrence interval in years, or null for an annual rule.

anchorYear int?

The year the recurrence interval is measured from, or null to anchor on fromYear (or year zero when also unbounded).

Exceptions

ArgumentNullException

territories, onlyYears, or exceptYears is null.

Properties

AnchorYear

Gets the anchor year the recurrence interval is measured from.

public int? AnchorYear { get; }

Property Value

int?

The anchor year, or null to anchor on FromYear (or year zero when also unbounded).

Calendar

Gets the calendar system the rule's strategy is expressed in.

public CalendarSystem Calendar { get; }

Property Value

CalendarSystem

The configured CalendarSystem.

EveryYears

Gets the recurrence interval in years.

public int? EveryYears { get; }

Property Value

int?

The cadence (for example 4 for every fourth year), or null for an annual rule.

ExceptYears

Gets the explicit exclusion years.

public IReadOnlyList<int> ExceptYears { get; }

Property Value

IReadOnlyList<int>

The years the rule is suppressed for; empty when there are none.

FromYear

Gets the first applicable Gregorian year.

public int? FromYear { get; }

Property Value

int?

The lower year bound, or null when unbounded.

OnlyYears

Gets the explicit inclusion years.

public IReadOnlyList<int> OnlyYears { get; }

Property Value

IReadOnlyList<int>

The years the rule is restricted to; empty when unrestricted.

Territories

Gets the explicit territories the rule applies to.

public IReadOnlyList<string> Territories { get; }

Property Value

IReadOnlyList<string>

The territory codes; empty when the rule is global.

ToYear

Gets the last applicable Gregorian year.

public int? ToYear { get; }

Property Value

int?

The upper year bound, or null when unbounded.

Methods

AppliesTo(string, int)

Determines whether the rule applies to the supplied territory and Gregorian year.

public bool AppliesTo(string territory, int year)

Parameters

territory string

The requested territory code.

year int

The Gregorian year being resolved.

Returns

bool

true if the rule applies; otherwise false.

MatchSpecificity(string)

Returns the specificity of this rule's territory match against the supplied territory, used to let a narrower rule shadow a broader same-concept rule.

public int MatchSpecificity(string territory)

Parameters

territory string

The requested territory code.

Returns

int

The length of the most specific matching territory code (an exact or parent match), 0 when the rule is global (no territories), or -1 when the rule does not match.

MatchesTerritory(string)

Determines whether the rule's territories include, or are a parent of, the supplied territory.

public bool MatchesTerritory(string territory)

Parameters

territory string

The requested territory code.

Returns

bool

true if the territory matches; otherwise false.

Applies to

ProductVersions
.NET8, 10

See Also