Compare commits
5 Commits
28f0ea9fce
...
5a55ad6ef0
Author | SHA1 | Date | |
---|---|---|---|
5a55ad6ef0 | |||
5a77958e8d | |||
a1e7f4629a | |||
efc2582c36 | |||
a72f5a5019 |
@ -131,17 +131,52 @@ std::optional<ATBTariffPrepaid> getPrepaid(Configuration const *cfg, QDateTime c
|
||||
std::optional<ATBTariffPrepaid> value = std::nullopt;
|
||||
|
||||
int weekDay = dt.date().dayOfWeek();
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << dt.toString(Qt::ISODate) << weekDay;
|
||||
|
||||
ATBTime inputTime(dt.time());
|
||||
QDate d; // check if a special date is configured in tariff-file for this day
|
||||
auto const &prepaidRange = cfg->TariffPrepaids.equal_range(weekDay);
|
||||
|
||||
for (auto i = prepaidRange.first; i != prepaidRange.second; ++i) {
|
||||
ATBTariffPrepaid const &prepaid = i->second;
|
||||
TimeRange const &prepaidTimeRange = prepaid.m_range;
|
||||
if (inputTime >= prepaidTimeRange.m_start && inputTime < prepaidTimeRange.m_end) {
|
||||
value = value.value_or(i->second);
|
||||
if (!prepaid.m_date.isNull() && prepaid.m_date.isValid() && prepaid.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 = prepaidRange.first; i != prepaidRange.second; ++i) {
|
||||
ATBTariffPrepaid const &prepaid = i->second;
|
||||
if (!prepaid.m_date.isNull() && prepaid.m_date.isValid() && prepaid.m_date == d) {
|
||||
TimeRange const &prepaidTimeRange = prepaid.m_range;
|
||||
if (inputTime >= prepaidTimeRange.m_start && inputTime < prepaidTimeRange.m_end) {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << prepaidTimeRange.m_start.toString(Qt::ISODate);
|
||||
// qCritical() << __func__ << ":" << __LINE__ << prepaidTimeRange.m_end.toString(Qt::ISODate);
|
||||
value = value.value_or(i->second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "no special day" << dt.date().toString(Qt::ISODate);
|
||||
for (auto i = prepaidRange.first; i != prepaidRange.second; ++i) {
|
||||
ATBTariffPrepaid const &prepaid = i->second;
|
||||
if (prepaid.m_date.isNull() || !prepaid.m_date.isValid()) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "default";
|
||||
TimeRange const &prepaidTimeRange = prepaid.m_range;
|
||||
if (inputTime >= prepaidTimeRange.m_start && inputTime < prepaidTimeRange.m_end) {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << prepaidTimeRange.m_start.toString(Qt::ISODate);
|
||||
// qCritical() << __func__ << ":" << __LINE__ << prepaidTimeRange.m_end.toString(Qt::ISODate);
|
||||
value = value.value_or(i->second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -161,17 +196,48 @@ std::optional<ATBTariffCarryOver> 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;
|
||||
}
|
||||
|
||||
@ -186,17 +252,53 @@ std::optional<ATBTariffService> getService(Configuration const *cfg, QDateTime c
|
||||
std::optional<ATBTariffService> value = std::nullopt;
|
||||
|
||||
int weekDay = dt.date().dayOfWeek();
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << dt.toString(Qt::ISODate) << weekDay;
|
||||
|
||||
ATBTime inputTime(dt.time());
|
||||
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) {
|
||||
ATBTariffService const &service = i->second;
|
||||
TimeRange const &serviceTimeRange = service.m_range;
|
||||
if (inputTime >= serviceTimeRange.m_start && inputTime < serviceTimeRange.m_end) {
|
||||
value = value.value_or(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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
@ -210,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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,22 +554,22 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
.arg(netto_parking_time_in_minutes)
|
||||
.arg(free_parking_time_in_minutes);
|
||||
|
||||
if (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, inputDate.addSecs(brutto_parking_time_in_minutes * 60))) {
|
||||
if (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, dt)) {
|
||||
TimeRange const &carryOverTimeRange = co.value().m_range;
|
||||
free_parking_time_in_minutes += carryOverTimeRange.m_duration;
|
||||
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
||||
weekDay = dt.date().dayOfWeek();
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
||||
.arg(dt.toString(Qt::ISODate))
|
||||
.arg(weekDay)
|
||||
.arg(brutto_parking_time_in_minutes)
|
||||
.arg(netto_parking_time_in_minutes)
|
||||
.arg(free_parking_time_in_minutes);
|
||||
}
|
||||
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
||||
weekDay = dt.date().dayOfWeek();
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
||||
.arg(dt.toString(Qt::ISODate))
|
||||
.arg(weekDay)
|
||||
.arg(brutto_parking_time_in_minutes)
|
||||
.arg(netto_parking_time_in_minutes)
|
||||
.arg(free_parking_time_in_minutes);
|
||||
|
||||
if (std::optional<ATBTariffService> serv = getService(cfg, dt)) {
|
||||
TimeRange const &serviceTimeRange = serv.value().m_range;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user