From a867a490e6f5088525dd0d060af047e2f9f168c4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 17 Jun 2014 20:05:27 +0200 Subject: [PATCH] Improved details on the readers, regarding timestamp --- src/blackcore/vatsimbookingreader.cpp | 21 ++++++++++++++++++++- src/blackcore/vatsimdatafilereader.cpp | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/blackcore/vatsimbookingreader.cpp b/src/blackcore/vatsimbookingreader.cpp index 6239e7358..0903c8f77 100644 --- a/src/blackcore/vatsimbookingreader.cpp +++ b/src/blackcore/vatsimbookingreader.cpp @@ -59,6 +59,24 @@ namespace BlackCore if (doc.setContent(xmlData)) { + QDomNode timestamp = doc.elementsByTagName("timestamp").at(0); + QString ts = timestamp.toElement().text().trimmed(); + Q_ASSERT(!ts.isEmpty()); + if (ts.isEmpty()) + { + // fallback + m_updateTimestamp = QDateTime::currentDateTimeUtc(); + } + else + { + // normally the timestamp is always updated from backend + // if this changes in the future we're prepared + QDateTime fileTimestamp = QDateTime::fromString(ts, "yyyy-MM-dd HH:mm:ss"); + fileTimestamp.setTimeSpec(Qt::UTC); + if (this->m_updateTimestamp == fileTimestamp) return; // nothing to do + this->m_updateTimestamp = fileTimestamp; + } + QDomNode atc = doc.elementsByTagName("atcs").at(0); QDomNodeList bookingNodes = atc.toElement().elementsByTagName("booking"); int size = bookingNodes.size(); @@ -93,11 +111,13 @@ namespace BlackCore else if (name == "time_end") { QDateTime t = QDateTime::fromString(value, "yyyy-MM-dd HH:mm:ss"); + t.setTimeSpec(Qt::UTC); bookedStation.setBookedUntilUtc(t); } else if (name == "time_start") { QDateTime t = QDateTime::fromString(value, "yyyy-MM-dd HH:mm:ss"); + t.setTimeSpec(Qt::UTC); bookedStation.setBookedFromUtc(t); } } @@ -108,7 +128,6 @@ namespace BlackCore bookedStation.setController(user); bookedStations.push_back(bookedStation); } - m_updateTimestamp = QDateTime::currentDateTimeUtc(); emit this->dataRead(bookedStations); } // node diff --git a/src/blackcore/vatsimdatafilereader.cpp b/src/blackcore/vatsimdatafilereader.cpp index 2b329953f..9dbda856d 100644 --- a/src/blackcore/vatsimdatafilereader.cpp +++ b/src/blackcore/vatsimdatafilereader.cpp @@ -243,7 +243,10 @@ namespace BlackCore QString dts = updateParts.at(1).trimmed(); QDateTime dt = QDateTime::fromString(dts, "yyyyMMddHHmmss"); dt.setOffsetFromUtc(0); - if (dt == this->m_updateTimestamp) return; // still same data, terminate + if (dt == this->m_updateTimestamp) + { + return; // still same data, terminate + } this->m_updateTimestamp = dt; } }