From efc2582c36b410d9ea867c8da77b1c7fd1f3633c Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 2 Oct 2024 15:17:00 +0200 Subject: [PATCH] getCarryOver(): Check for special days (holidays) with carry-over-sections. Holidays have higher priority than usual days. --- library/src/calculator_functions.cpp | 41 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) 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; }