diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index c717675..60f18ae 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -196,17 +196,48 @@ std::optional 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; }