getOutOfService():

Check for special days (holidays) with out-of-service-time-ranges.
	Holidays have higher priority than usual days ("default").
This commit is contained in:
Gerhard Hoffmann 2024-10-02 15:19:32 +02:00
parent a1e7f4629a
commit 5a77958e8d

View File

@ -312,29 +312,50 @@ std::optional<ATBTariffOutOfService> getOutOfService(Configuration const *cfg, Q
std::optional<ATBTariffOutOfService> 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;
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) {
value = value.value_or(i->second);
return value;
// 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;
}
}
}
}