getCarryOver():

Check for special days (holidays) with carry-over-sections.
	Holidays have higher priority than usual days.
This commit is contained in:
Gerhard Hoffmann 2024-10-02 15:17:00 +02:00
parent a72f5a5019
commit efc2582c36

View File

@ -196,17 +196,48 @@ std::optional<ATBTariffCarryOver> getCarryOver(Configuration const *cfg, QDateTi
ATBTime inputTime(dt.time());
auto const &carryOverRange = cfg->TariffCarryOvers.equal_range(weekDay);
QDate d; // check if a special date is configured in tariff-file for this day
for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) {
ATBTariffCarryOver const &carryOver = i->second;
TimeRange const &carryOverTimeRange = carryOver.m_range;
if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) {
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(carryOver);
if (!carryOver.m_date.isNull() && carryOver.m_date.isValid() && carryOver.m_date == dt.date()) {
d = dt.date();
// qCritical() << __func__ << ":" << __LINE__ << "found special day" << d.toString(Qt::ISODate);
break;
}
}
if (!d.isNull() && d.isValid()) {
for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) {
ATBTariffCarryOver const &carryOver = i->second;
if (!carryOver.m_date.isNull() && carryOver.m_date.isValid() && carryOver.m_date == d) {
TimeRange const &carryOverTimeRange = carryOver.m_range;
if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) {
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(carryOver);
break;
}
}
}
} else {
// qCritical() << __func__ << ":" << __LINE__ << "no special day" << dt.date().toString(Qt::ISODate);
for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) {
ATBTariffCarryOver const &carryOver = i->second;
if (carryOver.m_date.isNull() || !carryOver.m_date.isValid()) {
// qCritical() << __func__ << ":" << __LINE__ << "default";
TimeRange const &carryOverTimeRange = carryOver.m_range;
if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) {
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(carryOver);
break;
}
}
}
}
return value;
}