| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | IsHoliday | (hzSDate&,uint32_t,) |
Declared in file: hzCron.h
Defined in file : hzCron.cpp
Function Logic:
Function body:
uint32_t IsHoliday (hzSDate& date)uint32_t holFlags,
{
// Arguments: 1) date Short form date
// 2) holFlags By default, this will select UK public holidays
//
// Returns: >0 A bitwise value indicating which holiday the given date is
// 0 If the given date is not a holiday
_hzfunc(__func__) ;
static hzMapM<hzSDate,uint32_t> hols ; // Known public holidays
static hzSet<uint32_t> hol_year ; // Holidays calculated for year
hzXDate moon ; // Date & time of full moon
hzXDate limt ; // Run-up to full moon date
hzSDate test ; // Date to test if moon date is Good Friday/Easter Sunday
uint32_t Lo ; // First possible holiday date
uint32_t Hi ; // Last possible holiday date
uint32_t theday = 0; // Holiday found
uint32_t nIndex ; // Holiday iterator
if (!holFlags)
holFlags = HZ_PUBHOL_ALLUK ;
if (!hol_year.Exists(date.Year()))
{
// If we have not yet calculated the holidays for the supplied year, do so now.
hol_year.Insert(date.Year()) ;
// New year
test.SetDate(date.Year(), 1,1);
hols.Insert(test, HZ_PUBHOL_NEWYEAR) ;
if (test.Dow() == 5)
test += 2;
if (test.Dow() == 6)
test += 1;
hols.Insert(test, HZ_PUBHOL_LUE_NEWYEAR) ;
// Calc Easter. Sunday after full moon after spring Equinox (March 21st)
moon.SetDateTime("20120109083006") ;
limt.SetDate(date.Year(), 3,21);
limt.SetTime(0,0,0);
for (; moon <&eq; limt ; moon.altdate(SECOND, 2541298));
for (; moon.Dow() != 6; moon.altdate(DAY, 1));
test.SetDate(date.Year(), moon.Month(), moon.Day()) ;
test -= 2; hols.Insert(test, HZ_PUBHOL_GOOD_FRIDAY) ;
test += 2; hols.Insert(test, HZ_PUBHOL_EASTER_SUNDAY) ;
test += 1; hols.Insert(test, HZ_PUBHOL_EASTER_MONDAY) ;
// Mayday, First Monday in May
test.SetDate(date.Year(), 5,1);
if (test.Dow() == 5)
test += 2;
if (test.Dow() == 6)
test += 1;
hols.Insert(test, HZ_PUBHOL_MAYDAY) ;
// Last Monday in May
test.SetDate(date.Year(), 5,31);
for (; test.Dow() ; test -= 1);
hols.Insert(test, HZ_PUBHOL_SPRING) ;
// Last Monday in August
test.SetDate(date.Year(), 5,31);
for (; test.Dow() ; test -= 1);
hols.Insert(test, HZ_PUBHOL_SUMMER) ;
// Always Dec 25th
test.SetDate(date.Year(), 12,25);
hols.Insert(test, HZ_PUBHOL_XMAS) ;
if (test.Dow() == 5)
test += 2;
if (test.Dow() == 6)
test += 1;
hols.Insert(test, HZ_PUBHOL_LUE_XMAS) ;
// Boxing day, always Dec 25th
test.SetDate(date.Year(), 12,26);
hols.Insert(test, HZ_PUBHOL_BOXING) ;
if (test.Dow() == 5)
test += 2;
if (test.Dow() == 6)
test += 1;
hols.Insert(test, HZ_PUBHOL_LUE_BOXING) ;
}
Lo = hols.First(date) ;
if (Lo < 0)
return false ;
Hi = hols.Last(date) ;
for (nIndex = Lo ; nIndex <&eq; Hi ; nIndex++)
theday |= hols.GetObj(nIndex) ;
return theday ;
}