Added overoaded versions for compute_price_for_parking_ticket() and
compute_duration_for_parking_ticket() using QDateTime parameters. Added new error code WRONG_ISO_TIME_FORMAT.
This commit is contained in:
parent
eebb6d926e
commit
e7606b6568
@ -5,6 +5,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef CALCULATE_LIBRARY_EXPORTS
|
#ifdef CALCULATE_LIBRARY_EXPORTS
|
||||||
@ -20,9 +21,9 @@ class Configuration;
|
|||||||
|
|
||||||
typedef Configuration parking_tariff_t;
|
typedef Configuration parking_tariff_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
//#ifdef __cplusplus
|
||||||
extern "C" {
|
//extern "C" {
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
struct CALCULATE_LIBRARY_API price_t {
|
struct CALCULATE_LIBRARY_API price_t {
|
||||||
uint32_t units;
|
uint32_t units;
|
||||||
@ -41,6 +42,7 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
NEGATIVE_PARING_TIME,
|
NEGATIVE_PARING_TIME,
|
||||||
INVALID_START_DATE,
|
INVALID_START_DATE,
|
||||||
WRONG_PARAM_VALUES,
|
WRONG_PARAM_VALUES,
|
||||||
|
WRONG_ISO_TIME_FORMAT,
|
||||||
ABOVE_MAX_PARKING_TIME,
|
ABOVE_MAX_PARKING_TIME,
|
||||||
BELOW_MIN_PARKING_TIME,
|
BELOW_MIN_PARKING_TIME,
|
||||||
BELOW_MIN_PARKING_PRICE,
|
BELOW_MIN_PARKING_PRICE,
|
||||||
@ -92,6 +94,8 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
case State::INVALID_START_DATE:
|
case State::INVALID_START_DATE:
|
||||||
s = "INVALID_START_DATE";
|
s = "INVALID_START_DATE";
|
||||||
break;
|
break;
|
||||||
|
case State::WRONG_ISO_TIME_FORMAT:
|
||||||
|
s = "WRONG_ISO_TIME_FORMAT";
|
||||||
}
|
}
|
||||||
return s + ":" + m_desc;
|
return s + ":" + m_desc;
|
||||||
}
|
}
|
||||||
@ -111,13 +115,25 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
time_t end_parking_time,
|
time_t end_parking_time,
|
||||||
struct price_t *price);
|
struct price_t *price);
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
QDateTime const &end_parking_time,
|
||||||
|
struct price_t *price);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
double cost,
|
double cost,
|
||||||
QString &duration);
|
QString &duration);
|
||||||
#ifdef __cplusplus
|
|
||||||
} // extern "C"
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
#endif
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
double cost,
|
||||||
|
QDateTime &ticketEndTime);
|
||||||
|
//#ifdef __cplusplus
|
||||||
|
//} // extern "C"
|
||||||
|
//#endif
|
||||||
|
|
||||||
#endif // CALCULATE_PRICE_H
|
#endif // CALCULATE_PRICE_H
|
||||||
|
@ -139,6 +139,57 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
QDateTime const &end_parking_time,
|
||||||
|
struct price_t *price) {
|
||||||
|
CalcState calcState;
|
||||||
|
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
||||||
|
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
||||||
|
|
||||||
|
int const duration = (end_parking_time.toSecsSinceEpoch() -
|
||||||
|
start_parking_time.toMSecsSinceEpoch()) / 60;
|
||||||
|
|
||||||
|
if (duration < 0) {
|
||||||
|
calcState.setDesc(QString("end=%1, start=%2")
|
||||||
|
.arg(end_parking_time.toString(Qt::ISODate),
|
||||||
|
start_parking_time.toString(Qt::ISODate)));
|
||||||
|
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
||||||
|
}
|
||||||
|
if (duration > maxMin) {
|
||||||
|
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(duration, maxMin));
|
||||||
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
|
}
|
||||||
|
if (duration < minMin) {
|
||||||
|
calcState.setDesc(QString("duration=%1, minMin=%2").arg(duration, minMin));
|
||||||
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
||||||
|
}
|
||||||
|
if (duration == 0) {
|
||||||
|
memset(price, 0x00, sizeof(*price));
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_parking_time.isValid()) {
|
||||||
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
|
double cost = calculator.GetCostFromDuration(
|
||||||
|
tariff, PaymentOption::Option1,
|
||||||
|
cs.toLocal8Bit().constData(),
|
||||||
|
duration, false, true);
|
||||||
|
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
||||||
|
if (cost < minCost) {
|
||||||
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
||||||
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
||||||
|
}
|
||||||
|
price->units = cost;
|
||||||
|
price->netto = cost;
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
@ -154,6 +205,35 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
price, false, true).c_str();
|
price, false, true).c_str();
|
||||||
|
QDateTime d = QDateTime::fromString(duration);
|
||||||
|
if (!d.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
double price,
|
||||||
|
QDateTime &ticketEndTime) {
|
||||||
|
CalcState calcState;
|
||||||
|
if (start_parking_time.isValid()) {
|
||||||
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
|
QString endTime = calculator.GetDurationFromCost(
|
||||||
|
tariff, PaymentOption::Option1,
|
||||||
|
cs.toLocal8Bit().constData(),
|
||||||
|
price, false, true).c_str();
|
||||||
|
ticketEndTime = QDateTime::fromString(endTime);
|
||||||
|
if (!ticketEndTime.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return calcState.set(CalcState::State::INVALID_START_DATE);
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user