Compare commits

...

4 Commits

Author SHA1 Message Date
275c3ec869 compute_price_for_parking_ticket():
Pass start-date-time to parking-time-checker.
2024-09-03 11:19:23 +02:00
6d2bde1fe9 getPaymentOptionIndex():
Fix: make sure only one payment option can be chosen.
2024-09-03 11:17:31 +02:00
f02521d3c2 parseWeekDay():
for the park-time-limit checking take into account that the
 	start-date-time and end-date-time are on different days.
2024-09-03 11:15:08 +02:00
75f1c1bb76 Checking parking-time-limit:
provide start-date-time as well, because the limit counts only
	from one day to following day (e.g. Sunday to Monday or from
	holiday to next day).
2024-09-03 11:10:24 +02:00
3 changed files with 131 additions and 110 deletions

View File

@ -10,7 +10,9 @@ struct ATBTariffCarryOverSettings {
// parking time limit not violated: return false, otherwise: return true.
using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
QDateTime const &endTime, int paymentOptionIndex)>;
QDateTime const &startTime,
QDateTime const &endTime,
int paymentOptionIndex)>;
int m_duration;
QTime m_start;
@ -24,7 +26,8 @@ struct ATBTariffCarryOverSettings {
: m_duration(0)
, m_start(QTime())
, m_end(QTime())
, m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&, QDateTime const &, int) { return false; })
, m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&,
QDateTime const&, QDateTime const&, int) { return false; })
, m_parking_time_limit(QTime())
, m_about_to_exceed_parking_time_limit(QTime()) {}
@ -41,8 +44,10 @@ struct ATBTariffCarryOverSettings {
, m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) {
}
bool parkingTimeLimitExceeded(QDateTime const &endTime, int paymentOptionIndex) const {
return m_parkingTimeLimitChecker(*this, endTime, paymentOptionIndex);
bool parkingTimeLimitExceeded(QDateTime const &startTime,
QDateTime const &endTime,
int paymentOptionIndex) const {
return m_parkingTimeLimitChecker(*this, startTime, endTime, paymentOptionIndex);
}
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {

View File

@ -852,7 +852,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(end_parking_time, paymentOptionIndex);
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(effectiveStartTime,
end_parking_time,
paymentOptionIndex);
if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(end_parking_time.time().toString(Qt::ISODate)));
@ -1138,7 +1140,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
itr != rangeEnd;
++itr) {
ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(ticketEndTime, paymentOptionIndex);
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
ticketEndTime,
paymentOptionIndex);
if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(ticketEndTime.time().toString(Qt::ISODate)));

View File

@ -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,8 +120,10 @@ 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 &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__
@ -139,6 +141,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
}
return false;
};
}
@ -151,8 +154,10 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
}
parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs,
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__
@ -170,6 +175,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
}
return false;
};
}
@ -251,8 +257,10 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
}
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
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__
@ -268,6 +276,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
}
return false;
};
} else
@ -280,8 +289,10 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
}
}
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
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__
@ -297,6 +308,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
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) {
@ -1536,6 +1547,11 @@ int getPaymentOptionIndex(Configuration const &cfg) {
QDateTime const dt = QDateTime::currentDateTime();
int const dayOfWeek = dt.date().dayOfWeek();
if (isHoliday(cfg, dt)) {
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
return opt;
}
} else {
switch (dayOfWeek) {
case (int)Qt::Monday: {
if (pop_business_hours & BusinessHours::MON) {
@ -1573,11 +1589,6 @@ int getPaymentOptionIndex(Configuration const &cfg) {
}
} break;
}
if (isHoliday(cfg, dt)) {
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
return opt;
}
}
}
@ -1841,6 +1852,7 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
bool isHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek();
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
iter != rEnd;
++iter) {