diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index d944ec4..1725d9f 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -312,29 +312,50 @@ std::optional getOutOfService(Configuration const *cfg, Q std::optional value = std::nullopt; int weekDay = dt.date().dayOfWeek(); + // qCritical() << __func__ << ":" << __LINE__ << dt.toString(Qt::ISODate) << weekDay; + ATBTime inputTime(dt.time()); QDate date; auto const &outOfServiceRange = cfg->TariffOutOfServices.equal_range(weekDay); + + QDate d; // check if a special date is configured in tariff-file for this day for (auto i = outOfServiceRange.first; i != outOfServiceRange.second; ++i) { ATBTariffOutOfService const &outOfService = i->second; - TimeRange const &outOfServiceTimeRange = outOfService.m_range; - if (outOfService.m_date == dt.date()) { - date = dt.date(); - if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) { - value = value.value_or(i->second); - return value; - } + if (!outOfService.m_date.isNull() && outOfService.m_date.isValid() && outOfService.m_date == dt.date()) { + d = dt.date(); + // qCritical() << __func__ << ":" << __LINE__ << "found special day" << d.toString(Qt::ISODate); + break; } } - if (date.isNull() || !date.isValid()) { + if (!d.isNull() && d.isValid()) { for (auto i = outOfServiceRange.first; i != outOfServiceRange.second; ++i) { ATBTariffOutOfService const &outOfService = i->second; - TimeRange const &outOfServiceTimeRange = outOfService.m_range; - if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) { - value = value.value_or(i->second); - return value; + + if (!outOfService.m_date.isNull() && outOfService.m_date.isValid() && outOfService.m_date == d) { + TimeRange const &outOfServiceTimeRange = outOfService.m_range; + if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) { + // qCritical() << __func__ << ":" << __LINE__ << outOfServiceTimeRange.m_start.toString(Qt::ISODate); + // qCritical() << __func__ << ":" << __LINE__ << outOfServiceTimeRange.m_end.toString(Qt::ISODate); + value = value.value_or(outOfService); + break; + } + } + } + } else { + // qCritical() << __func__ << ":" << __LINE__ << "no special day" << dt.date().toString(Qt::ISODate); + for (auto i = outOfServiceRange.first; i != outOfServiceRange.second; ++i) { + ATBTariffOutOfService const &outOfService = i->second; + if (outOfService.m_date.isNull() || !outOfService.m_date.isValid()) { + // qCritical() << __func__ << ":" << __LINE__ << "default"; + TimeRange const &outOfServiceTimeRange = outOfService.m_range; + if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) { + // qCritical() << __func__ << ":" << __LINE__ << outOfServiceTimeRange.m_start.toString(Qt::ISODate); + // qCritical() << __func__ << ":" << __LINE__ << outOfServiceTimeRange.m_end.toString(Qt::ISODate); + value = value.value_or(outOfService); + break; + } } } }