Compare commits
4 Commits
f47695de8b
...
275c3ec869
Author | SHA1 | Date | |
---|---|---|---|
275c3ec869 | |||
6d2bde1fe9 | |||
f02521d3c2 | |||
75f1c1bb76 |
@ -10,7 +10,9 @@ struct ATBTariffCarryOverSettings {
|
|||||||
|
|
||||||
// parking time limit not violated: return false, otherwise: return true.
|
// parking time limit not violated: return false, otherwise: return true.
|
||||||
using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
|
using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
|
||||||
QDateTime const &endTime, int paymentOptionIndex)>;
|
QDateTime const &startTime,
|
||||||
|
QDateTime const &endTime,
|
||||||
|
int paymentOptionIndex)>;
|
||||||
|
|
||||||
int m_duration;
|
int m_duration;
|
||||||
QTime m_start;
|
QTime m_start;
|
||||||
@ -24,7 +26,8 @@ struct ATBTariffCarryOverSettings {
|
|||||||
: m_duration(0)
|
: m_duration(0)
|
||||||
, m_start(QTime())
|
, m_start(QTime())
|
||||||
, m_end(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_parking_time_limit(QTime())
|
||||||
, m_about_to_exceed_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) {
|
, m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parkingTimeLimitExceeded(QDateTime const &endTime, int paymentOptionIndex) const {
|
bool parkingTimeLimitExceeded(QDateTime const &startTime,
|
||||||
return m_parkingTimeLimitChecker(*this, endTime, paymentOptionIndex);
|
QDateTime const &endTime,
|
||||||
|
int paymentOptionIndex) const {
|
||||||
|
return m_parkingTimeLimitChecker(*this, startTime, endTime, paymentOptionIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {
|
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {
|
||||||
|
@ -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) {
|
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
|
||||||
ATBWeekDay const &wd = itr->second;
|
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) {
|
if (parkTimeLimitViolated) {
|
||||||
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
||||||
.arg(end_parking_time.time().toString(Qt::ISODate)));
|
.arg(end_parking_time.time().toString(Qt::ISODate)));
|
||||||
@ -1138,7 +1140,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
itr != rangeEnd;
|
itr != rangeEnd;
|
||||||
++itr) {
|
++itr) {
|
||||||
ATBWeekDay const &wd = itr->second;
|
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) {
|
if (parkTimeLimitViolated) {
|
||||||
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
||||||
.arg(ticketEndTime.time().toString(Qt::ISODate)));
|
.arg(ticketEndTime.time().toString(Qt::ISODate)));
|
||||||
|
@ -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,8 +120,10 @@ 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 &startTime,
|
||||||
QDateTime const &endTime,
|
QDateTime const &endTime,
|
||||||
int paymentOptionIndex) {
|
int paymentOptionIndex) {
|
||||||
|
if (startTime.date() < endTime.date()) { // start end end on different days
|
||||||
if (endTime.date().dayOfWeek() == (int)weekDay) {
|
if (endTime.date().dayOfWeek() == (int)weekDay) {
|
||||||
if (endTime.time() > cs.m_parking_time_limit) {
|
if (endTime.time() > cs.m_parking_time_limit) {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
@ -139,6 +141,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -151,8 +154,10 @@ 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 &startTime,
|
||||||
QDateTime const &endTime,
|
QDateTime const &endTime,
|
||||||
int paymentOptionIndex) {
|
int paymentOptionIndex) {
|
||||||
|
if (startTime.date() < endTime.date()) { // start end end on different days
|
||||||
if (previousDayHoliday(cfg, endTime)) {
|
if (previousDayHoliday(cfg, endTime)) {
|
||||||
if (endTime.time() > cs.m_parking_time_limit) {
|
if (endTime.time() > cs.m_parking_time_limit) {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
@ -170,6 +175,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -251,8 +257,10 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
|
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
|
||||||
|
QDateTime const &startTime,
|
||||||
QDateTime const &endTime,
|
QDateTime const &endTime,
|
||||||
int paymentOptionIndex) {
|
int paymentOptionIndex) {
|
||||||
|
if (startTime.date() < endTime.date()) { // start end end on different days
|
||||||
if (endTime.date().dayOfWeek() == (int)weekDay) {
|
if (endTime.date().dayOfWeek() == (int)weekDay) {
|
||||||
if (endTime.time() > cs.m_parking_time_limit) {
|
if (endTime.time() > cs.m_parking_time_limit) {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
@ -268,6 +276,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
} else
|
} else
|
||||||
@ -280,8 +289,10 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
|
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
|
||||||
|
QDateTime const &startTime,
|
||||||
QDateTime const &endTime,
|
QDateTime const &endTime,
|
||||||
int paymentOptionIndex) {
|
int paymentOptionIndex) {
|
||||||
|
if (startTime.date() < endTime.date()) { // start end end on different days
|
||||||
if (previousDayHoliday(cfg, endTime)) {
|
if (previousDayHoliday(cfg, endTime)) {
|
||||||
if (endTime.time() > cs.m_parking_time_limit) {
|
if (endTime.time() > cs.m_parking_time_limit) {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
@ -297,6 +308,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
|
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) {
|
||||||
@ -1536,6 +1547,11 @@ int getPaymentOptionIndex(Configuration const &cfg) {
|
|||||||
QDateTime const dt = QDateTime::currentDateTime();
|
QDateTime const dt = QDateTime::currentDateTime();
|
||||||
int const dayOfWeek = dt.date().dayOfWeek();
|
int const dayOfWeek = dt.date().dayOfWeek();
|
||||||
|
|
||||||
|
if (isHoliday(cfg, dt)) {
|
||||||
|
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch (dayOfWeek) {
|
switch (dayOfWeek) {
|
||||||
case (int)Qt::Monday: {
|
case (int)Qt::Monday: {
|
||||||
if (pop_business_hours & BusinessHours::MON) {
|
if (pop_business_hours & BusinessHours::MON) {
|
||||||
@ -1573,11 +1589,6 @@ int getPaymentOptionIndex(Configuration const &cfg) {
|
|||||||
}
|
}
|
||||||
} break;
|
} 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) {
|
bool isHoliday(Configuration const &cfg, QDateTime const &t) {
|
||||||
int const weekDay = t.date().dayOfWeek();
|
int const weekDay = t.date().dayOfWeek();
|
||||||
|
|
||||||
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
|
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
|
||||||
iter != rEnd;
|
iter != rEnd;
|
||||||
++iter) {
|
++iter) {
|
||||||
|
Loading…
Reference in New Issue
Block a user