From 44e2ce24a3a707dbd851f8219a22518e2f91714c Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 10 Oct 2024 11:30:53 +0200 Subject: [PATCH] Add helper computeMinutesUntilCarryOverEnd(). Used in new tariff-calculator. Replace of previous wrong approach of using m_range.duration. --- library/include/mobilisis/tariff_carryover.h | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/include/mobilisis/tariff_carryover.h b/library/include/mobilisis/tariff_carryover.h index 72e80bd..901881e 100644 --- a/library/include/mobilisis/tariff_carryover.h +++ b/library/include/mobilisis/tariff_carryover.h @@ -61,6 +61,28 @@ struct ATBTariffCarryOver { return QString("ERROR unknown carry over application: %1").arg(static_cast(m_carryOverIf)); } + int computeMinutesUntilCarryOverEnd(QDateTime const &dt) { + int minutes = 0; + QString end = m_range.m_end.toString(Qt::ISODate); + if (end == "24:00:00") { + QDateTime t = dt.addDays(1); + t.setTime(QTime(0,0,0)); + minutes = dt.secsTo(t) / 60; + } else { + QDateTime t(dt); + t.setTime(QTime::fromString(end, Qt::ISODate)); + minutes = dt.secsTo(t) / 60; + } + + if (minutes < 0 || minutes > m_range.m_duration) { + minutes = 0; + } + + // qCritical() << __func__ << ":" << __LINE__ << "minutes" << minutes; + + return minutes; + } + friend QDebug operator<<(QDebug debug, ATBTariffCarryOver const &co) { QDebugStateSaver saver(debug);