From c4e1d412a5321878552b14b47353f9fb6faba315 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 27 Sep 2024 13:31:01 +0200 Subject: [PATCH] Add some assinment operators to support assignment of tariff-time-ranges. --- library/include/mobilisis/atb_time.h | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/library/include/mobilisis/atb_time.h b/library/include/mobilisis/atb_time.h index 714100d..bc6f0cf 100644 --- a/library/include/mobilisis/atb_time.h +++ b/library/include/mobilisis/atb_time.h @@ -4,20 +4,42 @@ #include class ATBTime { - QDateTime const m_end; + static QDateTime const m_end; mutable QDateTime m_time; public: explicit ATBTime(); explicit ATBTime(int h, int m, int s = 0, int ms = 0); explicit ATBTime(QString const &time); + explicit ATBTime(QTime const &time); + + explicit ATBTime(ATBTime const &atbTime) { + m_time = atbTime.m_time; + } + + ATBTime &operator=(ATBTime && atbTime) { + m_time = std::move(atbTime.m_time); + return *this; + } + + ATBTime &operator=(ATBTime const &atbTime) { + m_time = atbTime.m_time; + return *this; + } + int hour() const { return m_time.time().hour(); } int minute() const { return m_time.time().minute(); } int second() const { return m_time.time().second(); } int msec() const { return m_time.time().msec(); } - int secsTo(QTime t) const { return m_time.time().secsTo(t); } + int secsTo(QString const &t) const { + if (t == "24:00:00") { + return m_time.secsTo(m_end); + } + return m_time.time().secsTo(QTime::fromString(t, Qt::ISODate)); + } + int msecsTo(QTime t) const { return m_time.time().msecsTo(t); } bool setHMS(int h, int m, int s, int ms = 0); @@ -48,10 +70,12 @@ public: friend bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept; friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept; friend bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept; + friend bool operator>=(const ATBTime &lhs, const ATBTime &rhs) noexcept; friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept; friend bool operator>(const ATBTime &lhs, const ATBTime &rhs) noexcept; friend bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept; - friend QDataStream &operator<<(QDataStream &out, ATBTime time); + friend QDataStream &operator<<(QDataStream &out, ATBTime const &time); + friend QDebug &operator<<(QDebug &out, ATBTime const &time); friend QDataStream &operator>>(QDataStream &in, ATBTime &time); };