Change interface: use QDateTime

- use QDateTime instead of char*-string
 - GetCostFromDuration: add end_datetime as a return value
This commit is contained in:
2023-05-16 15:31:53 +02:00
parent 88a0b6ebe2
commit eef94a3fb3
4 changed files with 40 additions and 32 deletions

View File

@@ -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);