Add helper computeMinutesUntilCarryOverEnd().

Used in new tariff-calculator. Replace of previous wrong approach of
        using m_range.duration.
This commit is contained in:
Gerhard Hoffmann 2024-10-10 11:30:53 +02:00
parent 5a55ad6ef0
commit 44e2ce24a3

View File

@ -61,6 +61,28 @@ struct ATBTariffCarryOver {
return QString("ERROR unknown carry over application: %1").arg(static_cast<int>(m_carryOverIf)); return QString("ERROR unknown carry over application: %1").arg(static_cast<int>(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) { friend QDebug operator<<(QDebug debug, ATBTariffCarryOver const &co) {
QDebugStateSaver saver(debug); QDebugStateSaver saver(debug);