Start parsing of pop_min_date_time and pop_max_date_time

This commit is contained in:
Gerhard Hoffmann 2024-05-03 13:50:10 +02:00
parent 1606a784a4
commit 33f43fb83d

View File

@ -9,6 +9,7 @@
#include <QString>
#include <QDebug>
#include <QRegularExpression>
/// <inheritdoc/>
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: