From 0ab833709c411c1e00bf4e9350e93241fa8bb88f Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 27 Sep 2024 13:40:18 +0200 Subject: [PATCH] Added struct ATBTariffCarryOver --- library/include/mobilisis/tariff_carryover.h | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/library/include/mobilisis/tariff_carryover.h b/library/include/mobilisis/tariff_carryover.h index 034fd63..72e80bd 100644 --- a/library/include/mobilisis/tariff_carryover.h +++ b/library/include/mobilisis/tariff_carryover.h @@ -3,6 +3,80 @@ #include +#include "time_range.h" + +enum class ApplyCarryOver { + NEVER = 0, + MATCH_PREV_DAY = 1, + MATCH_NEXT_DAY = 2, + ALWAYS = 3 +}; + +struct ATBTariffCarryOver { + int m_id; + QString m_weekDay; + TimeRange m_range; + QDate m_date; + ApplyCarryOver m_carryOverIf; + + explicit ATBTariffCarryOver() + : m_id(-1) + , m_carryOverIf(ApplyCarryOver::NEVER) { + } + + void setCarryOverIf(QString const &coif) { + if (coif == "never") { + m_carryOverIf = ApplyCarryOver::NEVER; + } else + if (coif == "match_prev_day") { + m_carryOverIf = ApplyCarryOver::MATCH_PREV_DAY; + } else + if (coif == "match_next_day") { + m_carryOverIf = ApplyCarryOver::MATCH_NEXT_DAY; + } else + if (coif == "always") { + m_carryOverIf = ApplyCarryOver::ALWAYS; + } else { + qCritical() << "ERROR unknown carry over application" << coif; + } + } + + ApplyCarryOver carryOverIf() const { + return m_carryOverIf; + } + + QString carryOverIfStr() const { + if (m_carryOverIf == ApplyCarryOver::NEVER) { + return "never"; + } + if (m_carryOverIf == ApplyCarryOver::ALWAYS) { + return "always"; + } + if (m_carryOverIf == ApplyCarryOver::MATCH_PREV_DAY) { + return "match prev day"; + } + if (m_carryOverIf == ApplyCarryOver::MATCH_NEXT_DAY) { + return "match next day"; + } + return QString("ERROR unknown carry over application: %1").arg(static_cast(m_carryOverIf)); + } + + friend QDebug operator<<(QDebug debug, ATBTariffCarryOver const &co) { + QDebugStateSaver saver(debug); + + debug.nospace() + << "\nTariffCarryOver:\n" + << " week day: " << co.m_weekDay << "\n" + << " date: " << co.m_date.toString(Qt::ISODate) << "\n" + << " id: " << co.m_id << "\n" + << " start: " << co.m_range.m_start << "\n" + << " end: " << co.m_range.m_end << "\n" + << " duration: " << co.m_range.m_duration << "\n" + << " carry over if: " << co.carryOverIfStr() << endl; + return debug; + } +}; + struct ATBCarryOver { struct week { int day;