getCarryOver():
Check for special days (holidays) with carry-over-sections. Holidays have higher priority than usual days.
This commit is contained in:
parent
a72f5a5019
commit
efc2582c36
@ -196,8 +196,22 @@ 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;
|
||||
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);
|
||||
@ -206,6 +220,23 @@ std::optional<ATBTariffCarryOver> getCarryOver(Configuration const *cfg, QDateTi
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user