Change interface: use QDateTime
- use QDateTime instead of char*-string - GetCostFromDuration: add end_datetime as a return value
This commit is contained in:
parent
88a0b6ebe2
commit
eef94a3fb3
@ -109,7 +109,7 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||
parking_tariff_t *tariff,
|
||||
time_t start_parking_time,
|
||||
time_t end_parking_time,
|
||||
@ -118,10 +118,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
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);
|
||||
int netto_parking_time,
|
||||
QDateTime &end_parking_time, // return value
|
||||
struct price_t *price); // return value
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
|
||||
parking_tariff_t *tariff,
|
||||
time_t start_parking_time,
|
||||
double cost,
|
||||
@ -131,7 +132,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
parking_tariff_t *tariff,
|
||||
QDateTime const &start_parking_time,
|
||||
double cost,
|
||||
QDateTime &ticketEndTime);
|
||||
QDateTime &ticketEndTime); // return value
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
||||
parking_tariff_t *tariff,
|
||||
|
@ -23,9 +23,10 @@ public:
|
||||
/// <param name="tariff_cfg">Pointer to configuration</param>
|
||||
/// <param name="vehicle_type">Type of vehicle</param>
|
||||
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
||||
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
||||
/// <param name="durationMin">Duration of parking in minutes</param>
|
||||
/// <returns>Returns cost (data type: double)</returns>
|
||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||
|
||||
// Daily ticket
|
||||
QString GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
|
||||
|
@ -92,10 +92,12 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// this is currently not used
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
parking_tariff_t *tariff,
|
||||
time_t start_parking_time, // in minutes
|
||||
time_t end_parking_time, // in minutes
|
||||
time_t end_parking_time, // netto time in minutes
|
||||
struct price_t *price) {
|
||||
CalcState calcState;
|
||||
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
||||
@ -129,11 +131,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
QTime const t(0, 0, 0);
|
||||
QDateTime start(d, t, Qt::UTC);
|
||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||
QDateTime end(start);
|
||||
if (start.isValid()) {
|
||||
QString cs = start.toString(Qt::ISODate);
|
||||
double cost = calculator.GetCostFromDuration(
|
||||
tariff, PaymentOption::Option1,
|
||||
cs.toLocal8Bit().constData(),
|
||||
start,
|
||||
end,
|
||||
duration, false, true);
|
||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
||||
if (cost < minCost) {
|
||||
@ -152,8 +155,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
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) {
|
||||
int netto_parking_time,
|
||||
QDateTime &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;
|
||||
@ -161,39 +166,37 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
// DEBUG
|
||||
qCritical() << "compute_price_for_parking_ticket() " << endl
|
||||
<< " start_parking_time: " << start_parking_time << endl
|
||||
<< " end_parking_time: " << end_parking_time << endl
|
||||
<< " netto_parking_time: " << netto_parking_time << endl
|
||||
<< " minMin: " << minMin << endl
|
||||
<< " maxMin: " << maxMin;
|
||||
|
||||
|
||||
int const duration = (end_parking_time.toSecsSinceEpoch() -
|
||||
start_parking_time.toSecsSinceEpoch()) / 60;
|
||||
|
||||
if (duration < 0) {
|
||||
if (netto_parking_time < 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));
|
||||
if (netto_parking_time > maxMin) {
|
||||
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(netto_parking_time).arg(maxMin));
|
||||
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||
}
|
||||
if (duration < minMin) {
|
||||
calcState.setDesc(QString("duration=%1, minMin=%2").arg(duration, minMin));
|
||||
if (netto_parking_time < minMin) {
|
||||
calcState.setDesc(QString("duration=%1, minMin=%2").arg(netto_parking_time).arg(minMin));
|
||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
||||
}
|
||||
if (duration == 0) {
|
||||
if (netto_parking_time == 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(), // starting time
|
||||
duration, false, true); // duration, minutes, netto
|
||||
start_parking_time, // starting time
|
||||
end_parking_time, // return value: end time
|
||||
netto_parking_time, // minutes, netto
|
||||
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));
|
||||
|
@ -318,7 +318,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
}
|
||||
|
||||
if(price >= min_price && total_duration_min >= minMin)
|
||||
qDebug() << "Valid until: " << inputDate.toString(Qt::ISODate);
|
||||
qDebug() << "GetDurationFromCost(): Valid until: " << inputDate.toString(Qt::ISODate);
|
||||
else
|
||||
{
|
||||
qDebug() << "Parking not allowed";
|
||||
@ -337,10 +337,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
///////////////////////////////////////
|
||||
|
||||
/// <inheritdoc/>
|
||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const char* start_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||
{
|
||||
// Get input date
|
||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
||||
QDateTime inputDate = start_datetime;
|
||||
|
||||
// Get day of week
|
||||
int weekdayId = 0;
|
||||
@ -422,7 +422,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
{
|
||||
LOG_DEBUG("- No workday found, trying to find next available day");
|
||||
inputDate = inputDate.addDays(1);
|
||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid));
|
||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid));
|
||||
}
|
||||
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
||||
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
||||
@ -435,7 +435,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
{
|
||||
inputDate = inputDate.addDays(1);
|
||||
inputDate.setTime(worktime_from);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
||||
}
|
||||
|
||||
// If overtime flag is set
|
||||
@ -465,7 +465,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
{
|
||||
LOG_DEBUG(" *** PREPAID *** Current time is past the time range end, searching for next available day");
|
||||
inputDate = inputDate.addDays(1);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,7 +516,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
||||
inputDate = inputDate.addDays(1);
|
||||
overtime = true;
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), total_duration_min);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, total_duration_min);
|
||||
}
|
||||
|
||||
// Increment input date minutes for each monetary unit
|
||||
@ -525,7 +525,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
total_cost += price_per_unit;
|
||||
|
||||
}
|
||||
qDebug() << "Valid until:" << inputDate.toString(Qt::ISODate).toStdString().c_str();
|
||||
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate).toStdString().c_str();
|
||||
|
||||
end_datetime = inputDate;
|
||||
|
||||
double ret_val = total_cost;
|
||||
total_cost = 0.0f;
|
||||
return ceil(ret_val);
|
||||
|
Loading…
Reference in New Issue
Block a user