Table of Contents

FixedDateStrategy Class

Definition

Namespace
Bodu.Globalization.Calendar.Algorithms
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
FixedDateStrategy.cs

Calculates a notable date that falls on a fixed month and day every year, optionally expressed in a non-Gregorian calendar system such as the Islamic, Hebrew, Persian, or Chinese lunisolar calendar.

public sealed class FixedDateStrategy : IDateCalculationStrategy
Inheritance
FixedDateStrategy
Implements
Inherited Members
Extension Methods

Remarks

For the Gregorian calendar the month and day are used directly. For a non-Gregorian system the month and day are interpreted in that system and projected onto the requested Gregorian year by Bodu.Globalization.Calendar.CalendarSystems, using a calendar-year sweep (for lunar and lunisolar systems whose year does not align with the Gregorian year) or a leap-month skip (for the Chinese lunisolar calendar).

// The rule shape this strategy realizes - a fixed civil date, authored via the builder
// (or <Fixed month="December" day="25" /> in the XML document form):
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
    .AddNotableDate("christmas", "Christmas Day", NotableDateCategory.PublicHoliday, c => c
        .AddRule("default", r => r.Fixed(12, 25)))
    .Build();

Constructors

FixedDateStrategy(int, int)

Initializes a new instance of the FixedDateStrategy class for the Gregorian calendar.

public FixedDateStrategy(int month, int day)

Parameters

month int

The one-based month of the occurrence.

day int

The one-based day of the occurrence.

Exceptions

ArgumentOutOfRangeException

month is not between 1 and 12, or day is not between 1 and 31.

FixedDateStrategy(int, int, CalendarSystem, bool, bool, string?)

Initializes a new instance of the FixedDateStrategy class for a specified calendar system.

public FixedDateStrategy(int month, int day, CalendarSystem calendar, bool sweepCalendarYears, bool skipLeapMonth, string? monthAlias)

Parameters

month int

The one-based month of the occurrence within the calendar system.

day int

The one-based day of the occurrence.

calendar CalendarSystem

The calendar system the month and day are expressed in.

sweepCalendarYears bool

Whether to sweep overlapping calendar years to locate the Gregorian occurrence.

skipLeapMonth bool

Whether a conventional Chinese month index skips an intercalary leap month.

monthAlias string

A Hebrew month alias whose number shifts in leap years, or null.

Exceptions

ArgumentOutOfRangeException

day is not between 1 and 31; or, for the Gregorian calendar, month is not between 1 and 12; or, for another calendar with no alias, month is not between 1 and 13.

Properties

Calendar

Gets the calendar system the month and day are expressed in.

public CalendarSystem Calendar { get; }

Property Value

CalendarSystem

The configured CalendarSystem.

Day

Gets the one-based day of the occurrence.

public int Day { get; }

Property Value

int

The day of the month.

Month

Gets the one-based month of the occurrence within its calendar system.

public int Month { get; }

Property Value

int

The month, or 0 when a MonthAlias supplies it at resolution time.

MonthAlias

Gets the Hebrew month alias whose number shifts in leap years.

public string? MonthAlias { get; }

Property Value

string

The alias, or null when the month is given numerically.

SkipLeapMonth

Gets a value indicating whether a conventional Chinese month index skips an intercalary leap month.

public bool SkipLeapMonth { get; }

Property Value

bool

true when a conventional month index steps over a leap month.

SweepCalendarYears

Gets a value indicating whether overlapping calendar years are swept to locate the Gregorian occurrence.

public bool SweepCalendarYears { get; }

Property Value

bool

true when the occurrence is located by sweeping calendar years.

Methods

Calculate(int, StrategyResolutionContext)

Calculates the occurrence of the notable date in the supplied Gregorian year.

public DateOnly? Calculate(int year, StrategyResolutionContext context)

Parameters

year int

The Gregorian year in which to calculate the occurrence.

context StrategyResolutionContext

The resolution context used by referential strategies to resolve other rules.

Returns

DateOnly?

The calculated occurrence, or null when the strategy produces no occurrence in year (for example a 29 February rule in a non-leap year).

CalculateAll(int, StrategyResolutionContext)

Calculates every occurrence of the fixed date within the supplied Gregorian year.

public IReadOnlyList<DateOnly> CalculateAll(int year, StrategyResolutionContext context)

Parameters

year int

The Gregorian year to calculate against.

context StrategyResolutionContext

The resolution context (unused; the date is self-contained).

Returns

IReadOnlyList<DateOnly>

The occurrences in chronological order. This is a single date for the Gregorian calendar, but a short Islamic month and day can recur twice in one Gregorian year.

Applies to

ProductVersions
.NET8, 10

See Also