parseWeekDay():

for the park-time-limit checking take into account that the
 	start-date-time and end-date-time are on different days.
This commit is contained in:
Gerhard Hoffmann 2024-09-03 11:15:08 +02:00
parent 75f1c1bb76
commit f02521d3c2

View File

@ -112,7 +112,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) { for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
if (l->name.IsString()) { if (l->name.IsString()) {
QString const &member = QString::fromStdString(l->name.GetString()); QString const &member = QString::fromStdString(l->name.GetString());
if (member == "default") { if (member == "prev_day_sunday?") {
if (l->value.IsArray()) { if (l->value.IsArray()) {
auto limits = l->value.GetArray(); auto limits = l->value.GetArray();
if (limits.Size() >= 2) { if (limits.Size() >= 2) {
@ -120,23 +120,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
} }
parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (endTime.date().dayOfWeek() == (int)weekDay) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (endTime.date().dayOfWeek() == (int)weekDay) {
<< QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4") if (endTime.time() > cs.m_parking_time_limit) {
.arg(weekDayName) qCritical() << __func__ << ":" << __LINE__
.arg(endTime.date().toString(Qt::ISODate)) << QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4")
.arg(endTime.time().toString(Qt::ISODate)) .arg(weekDayName)
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); .arg(endTime.date().toString(Qt::ISODate))
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -151,23 +154,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
} }
parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (previousDayHoliday(cfg, endTime)) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (previousDayHoliday(cfg, endTime)) {
<< QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4") if (endTime.time() > cs.m_parking_time_limit) {
.arg(weekDayName) qCritical() << __func__ << ":" << __LINE__
.arg(endTime.date().toString(Qt::ISODate)) << QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4")
.arg(endTime.time().toString(Qt::ISODate)) .arg(weekDayName)
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); .arg(endTime.date().toString(Qt::ISODate))
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -251,21 +257,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
} }
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (endTime.date().dayOfWeek() == (int)weekDay) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (endTime.date().dayOfWeek() == (int)weekDay) {
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") if (endTime.time() > cs.m_parking_time_limit) {
.arg(endTime.time().toString(Qt::ISODate)) qCritical() << __func__ << ":" << __LINE__
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -280,21 +289,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
} }
} }
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (previousDayHoliday(cfg, endTime)) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (previousDayHoliday(cfg, endTime)) {
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") if (endTime.time() > cs.m_parking_time_limit) {
.arg(endTime.time().toString(Qt::ISODate)) qCritical() << __func__ << ":" << __LINE__
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -1523,7 +1535,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
int getPaymentOptionIndex(Configuration const &cfg) { int getPaymentOptionIndex(Configuration const &cfg) {
int const numOptions = cfg.getAllPaymentOptions().size(); int const numOptions = cfg.getAllPaymentOptions().size();
for (int opt=0; opt < numOptions; ++opt) { for (int opt=0; opt < numOptions; ++opt) {