From 713b483918e5c7ce332668a97f02b3843e7a9696 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 27 Sep 2024 13:37:54 +0200 Subject: [PATCH] Added/fixed several functions. final testing needed. --- library/src/atb_time.cpp | 60 ++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/library/src/atb_time.cpp b/library/src/atb_time.cpp index e643c8d..3340e4d 100644 --- a/library/src/atb_time.cpp +++ b/library/src/atb_time.cpp @@ -1,30 +1,40 @@ #include "atb_time.h" +#include +QDateTime const ATBTime::m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate)); ATBTime::ATBTime() - : m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate)) - , m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) { + : m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) { } -ATBTime::ATBTime(int h, int m, int s, int ms) - : m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate)) - , m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) { +ATBTime::ATBTime(int h, int m, int /*s*/, int /*ms*/) + : m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) { - QTime t(h, m, s, ms); - m_time.setTime(t); + if (h == 24 && m == 0) { + m_time = m_end; + } else { + QTime const t(h, m, 0, 0); + m_time.setTime(t); + } } ATBTime::ATBTime(QString const &t) - : m_end(QDateTime::fromString("1970-01-02T00:00:00")) - , m_time(QDateTime::fromString("1970-01-01T00:00:00")) { + : m_time(QDateTime::fromString("1970-01-01T00:00:00")) { if (t == "24:00:00") { m_time = m_end; } else { - m_time.setTime(QTime::fromString(t, Qt::ISODate)); + QTime tmp = QTime::fromString(t, Qt::ISODate); + if (tmp.isValid()) { + m_time.setTime(tmp); + } } } +ATBTime::ATBTime(QTime const &t) + : m_time(QDateTime::fromString("1970-01-01T00:00:00")) { + m_time.setTime(t); +} QTime ATBTime::addMSecs(int ms) const { return m_time.time().addMSecs(ms); @@ -78,6 +88,9 @@ bool ATBTime::setHMS(int h, int m, int s, int ms) { } QString ATBTime::toString(Qt::DateFormat format) const { + if (m_time == m_end) { + return "24:00:00"; + } return m_time.time().toString(format); } @@ -86,11 +99,20 @@ bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept { } bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept { + if (rhs.m_time == rhs.m_end) { + return true; + } return lhs.m_time.time() <= rhs.m_time.time(); +} +bool operator>=(const ATBTime &lhs, const ATBTime &rhs) noexcept { + return lhs.m_time.time() >= rhs.m_time.time(); } bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept { + if (rhs.m_time == rhs.m_end) { + return true; + } return lhs.m_time.time() < rhs.m_time.time(); } @@ -102,8 +124,22 @@ bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept { return lhs.m_time.time() == rhs.m_time.time(); } -QDataStream &operator<<(QDataStream &out, ATBTime time) { - out << time.m_time.time(); +QDebug &operator<<(QDebug &debug, ATBTime const &time) { + QDebugStateSaver saver(debug); + if (time.m_time == time.m_end) { + debug.nospace() << QString("24:00:00"); + } else { + debug.nospace() << time.m_time.time().toString(Qt::ISODate); + } + return debug; +} + +QDataStream &operator<<(QDataStream &out, ATBTime const &time) { + if (time.m_time == time.m_end) { + out << QString("24:00:00"); + } else { + out << time.m_time.time(); + } return out; }