2024-09-16 10:42:08 +02:00
|
|
|
#ifndef ATB_TIME_H_INCLUDED
|
|
|
|
#define ATB_TIME_H_INCLUDED
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
class ATBTime {
|
2024-09-27 13:31:01 +02:00
|
|
|
static QDateTime const m_end;
|
2024-09-16 10:42:08 +02:00
|
|
|
mutable QDateTime m_time;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ATBTime();
|
|
|
|
explicit ATBTime(int h, int m, int s = 0, int ms = 0);
|
2024-09-17 16:53:45 +02:00
|
|
|
explicit ATBTime(QString const &time);
|
2024-09-27 13:31:01 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-09-16 10:42:08 +02:00
|
|
|
|
|
|
|
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(); }
|
|
|
|
|
2024-09-27 13:31:01 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2024-09-16 10:42:08 +02:00
|
|
|
int msecsTo(QTime t) const { return m_time.time().msecsTo(t); }
|
|
|
|
|
|
|
|
bool setHMS(int h, int m, int s, int ms = 0);
|
|
|
|
|
|
|
|
bool isNull() const { return m_time.time().isNull(); }
|
|
|
|
bool isValid() const { return m_time.time().isValid(); }
|
|
|
|
|
|
|
|
|
|
|
|
QTime addMSecs(int ms) const;
|
|
|
|
QTime addMSecs(int ms);
|
|
|
|
|
|
|
|
QTime addSecs(int s) const;
|
|
|
|
QTime addSecs(int s);
|
|
|
|
|
|
|
|
int msecsSinceStartOfDay() const;
|
|
|
|
QString toString(Qt::DateFormat format = Qt::TextDate) const;
|
|
|
|
|
|
|
|
|
|
|
|
static bool isValid(int h, int m, int s, int ms = 0);
|
|
|
|
|
|
|
|
static QTime currentTime() { return QDateTime::currentDateTime().time(); }
|
|
|
|
|
|
|
|
static constexpr QTime fromMSecsSinceStartOfDay(int msecs);
|
|
|
|
|
|
|
|
static QTime fromString(QString const &string, Qt::DateFormat format = Qt::TextDate);
|
|
|
|
static QTime fromString(QString const &string, const QString &format);
|
|
|
|
|
|
|
|
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;
|
2024-09-27 13:31:01 +02:00
|
|
|
friend bool operator>=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
2024-09-16 10:42:08 +02:00
|
|
|
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;
|
2024-09-27 13:31:01 +02:00
|
|
|
friend QDataStream &operator<<(QDataStream &out, ATBTime const &time);
|
|
|
|
friend QDebug &operator<<(QDebug &out, ATBTime const &time);
|
2024-09-16 10:42:08 +02:00
|
|
|
friend QDataStream &operator>>(QDataStream &in, ATBTime &time);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ATB_TIME_H_INCLUDED
|