Reformat to Unix.

Add overload for IsYearPeriodActive().
Add several helpers.
This commit is contained in:
Gerhard Hoffmann 2023-11-27 16:12:07 +01:00
parent e9047f995a
commit 684de4acd1

View File

@ -2,6 +2,7 @@
#include "tariff_log.h"
#include <QDebug>
#include <algorithm>
static int protection_counter = 0;
@ -195,6 +196,23 @@ bool Utilities::IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTim
}
}
bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt) {
if (std::none_of(cfg->YearPeriod.cbegin(),
cfg->YearPeriod.cend(),
[&dt](std::pair<int, ATBPeriodYear> const &year) {
QDate const d(2004, // 2004 is a leap year
dt.date().month(),
dt.date().day());
QDate const s(2004, year.second.pye_start_month, year.second.pye_start_day);
QDate const e(2004, year.second.pye_end_month, year.second.pye_end_day);
return (d >= s && d <= e);
})) {
qCritical() << "NO VALID YEAR PERIOD";
return false;
}
return true;
}
/// <inheritdoc/>
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
{
@ -317,3 +335,41 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
}
QTime Utilities::WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
return QTime::fromString(itr->second.pwd_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
return QTime::fromString(itr->second.pwd_time_to.c_str(), Qt::ISODate);
}
bool Utilities::isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId) {
return !isCarryOverNotSet(cfg, paymentMethodId);
}
bool Utilities::isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId) {
return (cfg->PaymentOption.find(paymentMethodId)->second.pop_carry_over < 1);
}
PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
if (cfg->PaymentOption.size() != 1) {
return PaymentMethod::Undefined;
}
std::multimap<int, ATBPaymentOption>::const_iterator it =
cfg->PaymentOption.cbegin();
switch (it->first) {
case PaymentMethod::Linear:
return PaymentMethod::Linear;
case PaymentMethod::Steps:
return PaymentMethod::Steps;
case PaymentMethod::Degressive:
return PaymentMethod::Degressive;
case PaymentMethod::Progressive:
return PaymentMethod::Progressive;
}
return PaymentMethod::Undefined;
}