Added/fixed several functions. final testing needed.
This commit is contained in:
		@@ -1,30 +1,40 @@
 | 
			
		||||
#include "atb_time.h"
 | 
			
		||||
#include <QDebugStateSaver>
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user