Add Catholic Feasts holiday authority class (US observances)

This includes a static function to calculate Easter that can be used for
other authorities.

Document the wxDateTimeWorkDays and wxDateTimeHolidayAuthority classes.

Closes #24094.
This commit is contained in:
Blake-Madden 2023-11-26 19:22:16 -05:00 committed by Vadim Zeitlin
parent 2c9fee3d6f
commit 5ba009e861
4 changed files with 912 additions and 13 deletions

View file

@ -1679,18 +1679,111 @@ const wxDateTime wxDefaultDateTime;
/**
@class wxDateTimeWorkDays
@todo Write wxDateTimeWorkDays documentation.
Holiday authority that classifies all Saturdays and Sundays
as holidays.
@library{wxbase}
@category{data}
*/
class wxDateTimeWorkDays
class wxDateTimeWorkDays : public wxDateTimeHolidayAuthority
{
public:
protected:
/**
Override which returns @true if provided date is a Saturday and Sunday.
*/
virtual bool DoIsHoliday(const wxDateTime& dt) const override;
/**
Override which returns all Saturdays and Sundays from a provided range.
*/
virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const override;
};
/**
@class wxDateTimeUSCatholicFeasts
Holiday authority that returns Catholic holy days of obligation,
as observed in the United States. This includes:
- Solemnity of Mary, Mother of God
- Easter (moveable feast)
- Ascension (moveable feast)
- Assumption of the Blessed Virgin Mary
- All Saints Day
- Immaculate Conception of the Blessed Virgin Mary
- Christmas
@library{wxbase}
@category{data}
@since 3.3.0
*/
class wxDateTimeUSCatholicFeasts : public wxDateTimeHolidayAuthority
{
public:
/**
Returns the date for Easter for a given year.
*/
static wxDateTime GetEaster(int year);
/**
Returns the date for Ascension for a given year.
Celebrated on the 40th day of Easter/
sixth Thursday after Easter Sunday.
*/
static wxDateTime GetThursdayAscension(int year);
/**
Returns the date for Ascension for a given year.
This is the same as GetThursdayAscension(),
but moved to the Sunday following the traditional Ascension
that falls on a Thursday.
*/
static wxDateTime GetSundayAscension(int year);
protected:
/**
Override which returns @true if provided date is a holy day of obligation.
*/
bool DoIsHoliday(const wxDateTime& dt) const override;
/**
Override to determine the holy days of obligation within a date range.
*/
size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const override;
};
/**
@class wxDateTimeChristianHolidays
Holiday authority that returns holidays common to all Christian religions.
This includes:
- Easter (moveable feast)
- Christmas
@library{wxbase}
@category{data}
@since 3.3.0
*/
class WXDLLIMPEXP_BASE wxDateTimeChristianHolidays : public wxDateTimeUSCatholicFeasts
{
protected:
/**
Override which returns @true if provided date is Easter or Christmas.
*/
bool DoIsHoliday(const wxDateTime& dt) const override;
/**
Override to determine the holidays within a date range.
*/
size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const override;
};
/**
@class wxDateSpan
@ -2231,7 +2324,12 @@ public:
/**
@class wxDateTimeHolidayAuthority
@todo Write wxDateTimeHolidayAuthority documentation.
Class which decides whether a given
date is a holiday and is used by all functions working with "work days".
New classes can be derived from this to determine specific holidays.
These classes should override DoIsHoliday() and DoGetHolidaysInRange(),
and be passed to wxDateTimeHolidayAuthority::AddAuthority() to be used.
@library{wxbase}
@category{data}
@ -2239,6 +2337,40 @@ public:
class wxDateTimeHolidayAuthority
{
public:
/// Returns @true if the given date is a holiday.
static bool IsHoliday(const wxDateTime& dt);
/**
Fills the provided array with all holidays in the given range, returns
the number of them.
*/
static size_t GetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays);
/// Clears the list of holiday authorities.
static void ClearAllAuthorities();
/**
Adds a new holiday authority.
The pointer will be deleted by wxDateTimeHolidayAuthority.
*/
static void AddAuthority(wxDateTimeHolidayAuthority* auth);
protected:
/**
This function should be overridden to determine whether
a given day is a holiday.
*/
virtual bool DoIsHoliday(const wxDateTime& dt) const = 0;
/**
This function should be overridden to fill an array with
all holidays between the two given dates.
*/
virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const = 0;
};