diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 347d6ce..938f379 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -372,8 +372,31 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu // progressive tariff: e.g. Neuhauser, Kirchdorf (743) (paymentMethodId == PaymentMethod::Progressive)) { - const QList stepList = Calculator::GetInstance().GetTimeSteps(tariff); - qCritical() << " compute_next_timestep() timeSteps:" << stepList; + QList &stepList = Calculator::GetInstance().GetTimeSteps(tariff); + int const size = stepList.size(); + if (size == 0) { + qCritical() << "compute_next_timestep() *ERROR empty step-list*"; + return currentTimeMinutes; + } + + qCritical() << " compute_next_timestep() first time step:" << stepList[0]; + qCritical() << " compute_next_timestep() timeSteps:" << stepList; + qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes; + + // consider time shift: the step-list might have been computed at a + // slightly different time point + int maxStep = -1; + if (size >= 2) { + maxStep = stepList[1] - stepList[0]; + } + int tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5); + if (std::abs(stepList[0] - currentTimeMinutes) <= tolerance) { + qCritical().noquote() + << QString(" compute_next_timestep() correction stepList[0]=%1 -> %2:") + .arg(stepList[0]).arg(currentTimeMinutes); + stepList[0] = currentTimeMinutes; + qCritical() << " compute_next_timestep() NEW timeSteps:" << stepList; + } int currentStepIndex = stepList.indexOf(currentTimeMinutes);