From 33f43fb83d15ad58477e7560e6d2391448dabd4d Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 3 May 2024 13:50:10 +0200 Subject: [PATCH] Start parsing of pop_min_date_time and pop_max_date_time --- library/src/configuration.cpp | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index 04ad26f..5318529 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -9,6 +9,7 @@ #include #include +#include /// MemberType Configuration::IdentifyJsonMember(const char* member_name) @@ -436,6 +437,62 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } } else if (strcmp(inner_obj_name, "pop_time_step_config") == 0) { this->currentPaymentOptions.last().pop_time_step_config = k->value.GetInt(); + } else if ((strcmp(inner_obj_name, "pop_min_date_time") == 0) + || (strcmp(inner_obj_name, "pop_max_date_time") == 0)) { + if (k->value.IsString()) { // -w0dFriT16:20:00 or +w0dMonT00:00:00 + static const QRegularExpression re(R"(([+-])w([0-9]+)d([A-Za-z]{3})T([0-9]{2}:[0-9]{2}:[0-9]{2}))"); + QString const &s = QString::fromStdString(k->value.GetString()); + QRegularExpressionMatch match = re.match(s); + if (match.hasMatch()) { + ATBPaymentOption::ATBMaxDateTime dt; + int lastCaptured = match.lastCapturedIndex(); + if (lastCaptured == 4) { + dt.direction = (match.captured(1) == "-") ? -1 : +1; + + bool ok; + uint8_t week = match.captured(2).toUInt(&ok); + if (ok) { + dt.week = week; + } + + QString const &day = match.captured(3); + if (day.compare("Mon", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Monday; + } else if (day.compare("Tue", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Tuesday; + } else if (day.compare("Wed", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Wednesday; + } else if (day.compare("Thu", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Thursday; + } else if (day.compare("Fri", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Friday; + } else if (day.compare("Sat", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Saturday; + } else if (day.compare("Sun", Qt::CaseInsensitive) == 0) { + dt.day = (int)Qt::Sunday; + } + + QTime t = QTime::fromString(match.captured(4), Qt::ISODate); + if (t.isValid()) { + dt.time = t; + } + } + + qCritical() << "DAY" << dt.day; + qCritical() << "DIR" << dt.direction; + qCritical() << "week" << dt.week; + qCritical() << "DIR" << dt.time; + + if (strcmp(inner_obj_name, "pop_min_date_time") == 0) { + this->currentPaymentOptions.last().pop_min_date_time = dt; + } else + if (strcmp(inner_obj_name, "pop_max_date_time") == 0) { + this->currentPaymentOptions.last().pop_max_date_time = dt; + exit(0); + } + + } + } } break; case MemberType::DurationType: