getService():

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

View File

@ -252,16 +252,52 @@ std::optional<ATBTariffService> getService(Configuration const *cfg, QDateTime c
std::optional<ATBTariffService> value = std::nullopt; std::optional<ATBTariffService> value = std::nullopt;
int weekDay = dt.date().dayOfWeek(); int weekDay = dt.date().dayOfWeek();
// qCritical() << __func__ << ":" << __LINE__ << dt.toString(Qt::ISODate) << weekDay;
ATBTime inputTime(dt.time()); ATBTime inputTime(dt.time());
auto const &serviceRange = cfg->TariffServices.equal_range(weekDay); auto const &serviceRange = cfg->TariffServices.equal_range(weekDay);
QDate d; // check if a special date is configured in tariff-file for this day
for (auto i = serviceRange.first; i != serviceRange.second; ++i) { for (auto i = serviceRange.first; i != serviceRange.second; ++i) {
ATBTariffService const &service = i->second; ATBTariffService const &service = i->second;
if (!service.m_date.isNull() && service.m_date.isValid() && service.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 = serviceRange.first; i != serviceRange.second; ++i) {
ATBTariffService const &service = i->second;
if (!service.m_date.isNull() && service.m_date.isValid() && service.m_date == d) {
TimeRange const &serviceTimeRange = service.m_range; TimeRange const &serviceTimeRange = service.m_range;
if (inputTime >= serviceTimeRange.m_start && inputTime < serviceTimeRange.m_end) { if (inputTime >= serviceTimeRange.m_start && inputTime < serviceTimeRange.m_end) {
value = value.value_or(i->second); // qCritical() << __func__ << ":" << __LINE__ << serviceTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << serviceTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(service);
break; break;
} }
} }
}
} else {
// qCritical() << __func__ << ":" << __LINE__ << "no special day" << dt.date().toString(Qt::ISODate);
for (auto i = serviceRange.first; i != serviceRange.second; ++i) {
ATBTariffService const &service = i->second;
if (service.m_date.isNull() || !service.m_date.isValid()) {
// qCritical() << __func__ << ":" << __LINE__ << "default";
TimeRange const &serviceTimeRange = service.m_range;
if (inputTime >= serviceTimeRange.m_start && inputTime < serviceTimeRange.m_end) {
// qCritical() << __func__ << ":" << __LINE__ << serviceTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << serviceTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(service);
break;
}
}
}
}
return value; return value;
} }