GetDailyTicketDuration: use QDateTime for timestamps
This commit is contained in:
parent
eef94a3fb3
commit
268d43cdea
@ -29,5 +29,5 @@ public:
|
|||||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, const QDateTime start_datetime, QDateTime & end_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
|
// Daily ticket
|
||||||
QString GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
|
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||||
};
|
};
|
||||||
|
@ -283,21 +283,18 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
|
|||||||
{
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
|
||||||
|
|
||||||
QString endTime = calculator.GetDailyTicketDuration(tariff,
|
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
||||||
cs.toLocal8Bit().constData(),
|
start_parking_time,
|
||||||
PaymentOption::Option1,
|
PaymentOption::Option1,
|
||||||
false); // carry over
|
false); // carry over
|
||||||
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << "compute_duration_for_daily_ticket(): ";
|
qCritical() << "compute_duration_for_daily_ticket(): ";
|
||||||
qCritical() << " endTime: " << endTime;
|
|
||||||
qCritical() << " ticketEndTime: " << ticketEndTime;
|
qCritical() << " ticketEndTime: " << ticketEndTime;
|
||||||
|
|
||||||
if (!ticketEndTime.isValid()) {
|
if (!ticketEndTime.isValid()) {
|
||||||
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
calcState.setDesc(QString("ticketEndTime=%1").arg(ticketEndTime.toString(Qt::ISODate)));
|
||||||
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,20 +19,25 @@ inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over)
|
QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over)
|
||||||
{
|
{
|
||||||
if(start_datetime.isNull() || start_datetime.isEmpty()) return NULL;
|
if(!start_datetime.isValid()) {
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
double day_price = 0.0f;
|
double day_price = 0.0f;
|
||||||
int current_special_day_id = -1;
|
int current_special_day_id = -1;
|
||||||
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toStdString().c_str(), ¤t_special_day_id, &day_price);
|
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toString(Qt::ISODate).toStdString().c_str(), ¤t_special_day_id, &day_price);
|
||||||
|
|
||||||
QDateTime inputDateTime = QDateTime::fromString(start_datetime, Qt::ISODate);
|
QDateTime inputDateTime = start_datetime;
|
||||||
QTime worktime_from;
|
QTime worktime_from;
|
||||||
QTime worktime_to;
|
QTime worktime_to;
|
||||||
|
|
||||||
int daily_card_price = cfg->PaymentOption.find(payment_option)->second.pop_daily_card_price;
|
int daily_card_price = cfg->PaymentOption.find(payment_option)->second.pop_daily_card_price;
|
||||||
if(daily_card_price <= 0) return "Daily ticket price zero or less";
|
if(daily_card_price <= 0) {
|
||||||
|
LOG_ERROR("Calculator::GetDailyTicketDuration(): Daily ticket price zero or less");
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
if(is_special_day)
|
if(is_special_day)
|
||||||
{
|
{
|
||||||
@ -46,21 +51,21 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
{
|
{
|
||||||
// Go to next day if outside worktime
|
// Go to next day if outside worktime
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(day_price <=0)
|
if(day_price <=0)
|
||||||
{
|
{
|
||||||
// Go to next day if special day price is 0
|
// Go to next day if special day price is 0
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
inputDateTime = inputDateTime.addSecs(diff);
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
||||||
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_card_price).c_str() + ", duration = " + to_string((diff/60)).c_str();
|
return inputDateTime;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -76,7 +81,7 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
if(found <=0)
|
if(found <=0)
|
||||||
{
|
{
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -92,18 +97,18 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
{
|
{
|
||||||
// Go to next day if outside worktime
|
// Go to next day if outside worktime
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
inputDateTime = inputDateTime.addSecs(diff);
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
||||||
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_card_price).c_str() + ", duration = " + to_string((diff/60)).c_str();
|
return inputDateTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return QDateTime();
|
||||||
}
|
}
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||||
|
Loading…
Reference in New Issue
Block a user