Add free functions isHoliday() to check if the current day is a holiday

and previousDayHoliday() to check if previous day (relative to endtime) is a
holiday.
This commit is contained in:
Gerhard Hoffmann 2024-09-02 17:05:32 +02:00
parent 68a1c24861
commit 349e9d8b06

View File

@ -1838,3 +1838,42 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
return value;
}
bool isHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek();
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
iter != rEnd;
++iter) {
if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
QDate const &d = iter->second.m_date;
if (!d.isNull() && d.isValid()) {
if (t.date() == d) {
return true;
}
}
}
}
return false;
}
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek();
int const previousWeekDay = (weekDay == static_cast<int>(Qt::Monday)) ?
static_cast<int>(Qt::Sunday) : (weekDay - 1);
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(previousWeekDay));
iter != rEnd;
++iter) {
if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
QDate const &d = iter->second.m_date;
if (!d.isNull() && d.isValid()) {
if (t.addDays(-1).date() == d) {
return true;
}
}
}
}
return false;
}