From f02521d3c23109cb04bd4caf3317119276ce79f9 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 3 Sep 2024 11:15:08 +0200 Subject: [PATCH] parseWeekDay(): for the park-time-limit checking take into account that the start-date-time and end-date-time are on different days. --- library/src/configuration.cpp | 143 ++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index 71020b4..3a78920 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -112,7 +112,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg, for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) { if (l->name.IsString()) { QString const &member = QString::fromStdString(l->name.GetString()); - if (member == "default") { + if (member == "prev_day_sunday?") { if (l->value.IsArray()) { auto limits = l->value.GetArray(); if (limits.Size() >= 2) { @@ -120,23 +120,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg, parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); } parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs, - QDateTime const &endTime, - int paymentOptionIndex) { - if (endTime.date().dayOfWeek() == (int)weekDay) { - if (endTime.time() > cs.m_parking_time_limit) { - qCritical() << __func__ << ":" << __LINE__ - << QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4") - .arg(weekDayName) - .arg(endTime.date().toString(Qt::ISODate)) - .arg(endTime.time().toString(Qt::ISODate)) - .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); - return true; - } - if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; - } else { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + QDateTime const &startTime, + QDateTime const &endTime, + int paymentOptionIndex) { + if (startTime.date() < endTime.date()) { // start end end on different days + if (endTime.date().dayOfWeek() == (int)weekDay) { + if (endTime.time() > cs.m_parking_time_limit) { + qCritical() << __func__ << ":" << __LINE__ + << QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4") + .arg(weekDayName) + .arg(endTime.date().toString(Qt::ISODate)) + .arg(endTime.time().toString(Qt::ISODate)) + .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); + return true; + } + if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; + } else { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + } } } return false; @@ -151,23 +154,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg, parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); } parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs, - QDateTime const &endTime, - int paymentOptionIndex) { - if (previousDayHoliday(cfg, endTime)) { - if (endTime.time() > cs.m_parking_time_limit) { - qCritical() << __func__ << ":" << __LINE__ - << QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4") - .arg(weekDayName) - .arg(endTime.date().toString(Qt::ISODate)) - .arg(endTime.time().toString(Qt::ISODate)) - .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); - return true; - } - if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; - } else { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + QDateTime const &startTime, + QDateTime const &endTime, + int paymentOptionIndex) { + if (startTime.date() < endTime.date()) { // start end end on different days + if (previousDayHoliday(cfg, endTime)) { + if (endTime.time() > cs.m_parking_time_limit) { + qCritical() << __func__ << ":" << __LINE__ + << QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4") + .arg(weekDayName) + .arg(endTime.date().toString(Qt::ISODate)) + .arg(endTime.time().toString(Qt::ISODate)) + .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); + return true; + } + if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; + } else { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + } } } return false; @@ -251,21 +257,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg, } parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs, - QDateTime const &endTime, - int paymentOptionIndex) { - if (endTime.date().dayOfWeek() == (int)weekDay) { - if (endTime.time() > cs.m_parking_time_limit) { - qCritical() << __func__ << ":" << __LINE__ - << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") - .arg(endTime.time().toString(Qt::ISODate)) - .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); - return true; - } - if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; - } else { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + QDateTime const &startTime, + QDateTime const &endTime, + int paymentOptionIndex) { + if (startTime.date() < endTime.date()) { // start end end on different days + if (endTime.date().dayOfWeek() == (int)weekDay) { + if (endTime.time() > cs.m_parking_time_limit) { + qCritical() << __func__ << ":" << __LINE__ + << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") + .arg(endTime.time().toString(Qt::ISODate)) + .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); + return true; + } + if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; + } else { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + } } } return false; @@ -280,21 +289,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg, } } parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs, - QDateTime const &endTime, - int paymentOptionIndex) { - if (previousDayHoliday(cfg, endTime)) { - if (endTime.time() > cs.m_parking_time_limit) { - qCritical() << __func__ << ":" << __LINE__ - << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") - .arg(endTime.time().toString(Qt::ISODate)) - .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); - return true; - } - if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; - } else { - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = - cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + QDateTime const &startTime, + QDateTime const &endTime, + int paymentOptionIndex) { + if (startTime.date() < endTime.date()) { // start end end on different days + if (previousDayHoliday(cfg, endTime)) { + if (endTime.time() > cs.m_parking_time_limit) { + qCritical() << __func__ << ":" << __LINE__ + << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") + .arg(endTime.time().toString(Qt::ISODate)) + .arg(cs.m_parking_time_limit.toString(Qt::ISODate)); + return true; + } + if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; + } else { + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = + cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; + } } } return false; @@ -1523,7 +1535,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const { int getPaymentOptionIndex(Configuration const &cfg) { - int const numOptions = cfg.getAllPaymentOptions().size(); for (int opt=0; opt < numOptions; ++opt) {