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
Exceptions
- ArgumentOutOfRangeException
monthis not between 1 and 12, ordayis 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
monthintThe one-based month of the occurrence within the calendar system.
dayintThe one-based day of the occurrence.
calendarCalendarSystemThe calendar system the month and day are expressed in.
sweepCalendarYearsboolWhether to sweep overlapping calendar years to locate the Gregorian occurrence.
skipLeapMonthboolWhether a conventional Chinese month index skips an intercalary leap month.
monthAliasstringA Hebrew month alias whose number shifts in leap years, or null.
Exceptions
- ArgumentOutOfRangeException
dayis not between 1 and 31; or, for the Gregorian calendar,monthis not between 1 and 12; or, for another calendar with no alias,monthis 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
0when 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
SkipLeapMonth
Gets a value indicating whether a conventional Chinese month index skips an intercalary leap month.
public bool SkipLeapMonth { get; }
Property Value
SweepCalendarYears
Gets a value indicating whether overlapping calendar years are swept to locate the Gregorian occurrence.
public bool SweepCalendarYears { get; }
Property Value
Methods
Calculate(int, StrategyResolutionContext)
Calculates the occurrence of the notable date in the supplied Gregorian year.
public DateOnly? Calculate(int year, StrategyResolutionContext context)
Parameters
yearintThe Gregorian year in which to calculate the occurrence.
contextStrategyResolutionContextThe resolution context used by referential strategies to resolve other rules.
Returns
CalculateAll(int, StrategyResolutionContext)
Calculates every occurrence of the fixed date within the supplied Gregorian year.
public IReadOnlyList<DateOnly> CalculateAll(int year, StrategyResolutionContext context)
Parameters
yearintThe Gregorian year to calculate against.
contextStrategyResolutionContextThe 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
| Product | Versions |
|---|---|
| .NET | 8, 10 |