Add own Time class (similar QTime)
This commit is contained in:
103
library/src/atb_time.cpp
Normal file
103
library/src/atb_time.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "atb_time.h"
|
||||
|
||||
|
||||
ATBTime::ATBTime()
|
||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
||||
}
|
||||
|
||||
ATBTime::ATBTime(int h, int m, int s, int ms)
|
||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
||||
|
||||
QTime t(h, m, s, ms);
|
||||
m_time.setTime(t);
|
||||
}
|
||||
|
||||
QTime ATBTime::addMSecs(int ms) const {
|
||||
return m_time.time().addMSecs(ms);
|
||||
}
|
||||
|
||||
QTime ATBTime::addMSecs(int ms) {
|
||||
QTime t = m_time.time();
|
||||
t = t.addMSecs(ms);
|
||||
m_time.setTime(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
QTime ATBTime::addSecs(int s) const {
|
||||
return m_time.time().addSecs(s);
|
||||
}
|
||||
|
||||
QTime ATBTime::addSecs(int s) {
|
||||
QTime t = m_time.time();
|
||||
t = t.addSecs(s);
|
||||
m_time.setTime(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
constexpr QTime ATBTime::fromMSecsSinceStartOfDay(int msecs) {
|
||||
return QTime::fromMSecsSinceStartOfDay(msecs);
|
||||
}
|
||||
|
||||
QTime ATBTime::fromString(QString const &string, Qt::DateFormat format) {
|
||||
return QTime::fromString(string, format);
|
||||
}
|
||||
|
||||
QTime ATBTime::fromString(QString const &string, QString const &format) {
|
||||
return QTime::fromString(string, format);
|
||||
}
|
||||
|
||||
bool ATBTime::isValid(int h, int m, int s, int ms) {
|
||||
return QTime(h, m, s, ms).isValid();
|
||||
}
|
||||
|
||||
int ATBTime::msecsSinceStartOfDay() const {
|
||||
return m_time.time().msecsSinceStartOfDay();
|
||||
}
|
||||
|
||||
bool ATBTime::setHMS(int h, int m, int s, int ms) {
|
||||
if (isValid(h, m, s, ms)) {
|
||||
QTime t(h, m, s, ms);
|
||||
m_time.setTime(t);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ATBTime::toString(Qt::DateFormat format) const {
|
||||
return m_time.time().toString(format);
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, ATBTime time) {
|
||||
out << time.m_time.time();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, ATBTime &time) {
|
||||
QTime t;
|
||||
in >> t;
|
||||
time.m_time.setTime(t);
|
||||
return in;
|
||||
}
|
Reference in New Issue
Block a user