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
calendarCalendarSystemThe calendar system the rule's strategy is expressed in.
fromYearint?The first applicable Gregorian year, or null for no lower bound.
toYearint?The last applicable Gregorian year, or null for no upper bound.
territoriesIEnumerable<string>The explicit territories the rule applies to.
onlyYearsIEnumerable<int>The explicit inclusion years, or an empty sequence for no restriction.
exceptYearsIEnumerable<int>The explicit exclusion years, or an empty sequence for no exclusions.
everyYearsint?The recurrence interval in years, or null for an annual rule.
anchorYearint?The year the recurrence interval is measured from, or null to anchor on
fromYear(or year zero when also unbounded).
Exceptions
- ArgumentNullException
territories,onlyYears, orexceptYearsis null.
Properties
AnchorYear
Gets the anchor year the recurrence interval is measured from.
public int? AnchorYear { get; }
Property Value
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
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
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
Methods
AppliesTo(string, int)
Determines whether the rule applies to the supplied territory and Gregorian year.
public bool AppliesTo(string territory, int year)
Parameters
Returns
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
territorystringThe requested territory code.
Returns
- int
The length of the most specific matching territory code (an exact or parent match),
0when the rule is global (no territories), or-1when 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
territorystringThe requested territory code.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |