From b0c4ad0e2e3572cdf6a30915027eb3b3dd302f63 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 12 Apr 2024 14:31:02 +0200 Subject: [PATCH] getCurrentPaymentOptionIndex(): start implementation. getPaymentOptions(): use new parameter paymentOptionIndex. --- library/src/configuration.cpp | 72 ++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index 812425f..6c13daf 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -3,6 +3,7 @@ #include "time_range_header.h" #include "tariff_timestep_config.h" #include "tariff_permit_type.h" +#include "tariff_business_hours.h" #include #include @@ -542,15 +543,76 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } } +int Configuration::getCurrentPaymentOptionIndex(QDateTime const &dt) const { + int const numOptions = getAllPaymentOptions().size(); -ATBPaymentOption const &Configuration::getPaymentOptions() const { - Q_ASSERT(!this->currentPaymentOptions.isEmpty()); - return this->currentPaymentOptions.at(0); + for (int opt=0; opt < numOptions; ++opt) { + uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours; + uint64_t p = 0; + switch (dt.date().dayOfWeek()) { + case (int)Qt::Monday: { + p = BusinessHours::MON; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Tuesday: { + p = BusinessHours::TUE; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Wednesday: { + p = BusinessHours::WED; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Thursday: { + p = BusinessHours::THU; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Friday: { + p = BusinessHours::FRI; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Saturday: { + p = BusinessHours::SAT; + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + case (int)Qt::Sunday: { + p = BusinessHours::SUN; + if (isHoliday(dt)) { + p |= BusinessHours::OFFICIAL_HOLIDAY; + } + if ((pop_business_hours & p) == p) { + return opt; + } + } break; + } + } + + return -1; } -ATBPaymentOption &Configuration::getPaymentOptions() { +bool Configuration::isHoliday(QDateTime const &dt) const { + return false; +} + +ATBPaymentOption const &Configuration::getPaymentOptions(int paymentOptionsIndex) const { Q_ASSERT(!this->currentPaymentOptions.isEmpty()); - return this->currentPaymentOptions[0]; + return this->currentPaymentOptions.at(paymentOptionsIndex); +} + +ATBPaymentOption &Configuration::getPaymentOptions(int paymentOptionsIndex) { + Q_ASSERT(!this->currentPaymentOptions.isEmpty()); + return this->currentPaymentOptions[paymentOptionsIndex]; } QVector const &Configuration::getAllPaymentOptions() const {