From 3d1a6f61463f022462c93a331add64af1cb48e94 Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Sun, 27 Aug 2023 16:18:42 +0100 Subject: [PATCH] ui/NavManager: parse location timestamp from API (#29665) --- selfdrive/ui/qt/maps/map_settings.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/maps/map_settings.cc b/selfdrive/ui/qt/maps/map_settings.cc index 52756abdc3..4d655be36c 100644 --- a/selfdrive/ui/qt/maps/map_settings.cc +++ b/selfdrive/ui/qt/maps/map_settings.cc @@ -15,6 +15,11 @@ static bool locationEqual(const QJsonValue &v1, const QJsonValue &v2) { return v1["latitude"] == v2["latitude"] && v1["longitude"] == v2["longitude"]; } +static qint64 convertTimestampToEpoch(const QString ×tamp) { + QDateTime dt = QDateTime::fromString(timestamp, Qt::ISODate); + return dt.isValid() ? dt.toSecsSinceEpoch() : 0; +} + MapSettings::MapSettings(bool closeable, QWidget *parent) : QFrame(parent) { setContentsMargins(0, 0, 0, 0); setAttribute(Qt::WA_NoMousePropagation); @@ -322,7 +327,8 @@ void NavManager::parseLocationsResponse(const QString &response, bool success) { auto remote_locations = doc.array(); for (QJsonValueRef loc : remote_locations) { auto obj = loc.toObject(); - obj.insert("time", getLastActivity(obj)); + auto serverTime = convertTimestampToEpoch(obj["modified"].toString()); + obj.insert("time", qMax(serverTime, getLastActivity(obj))); loc = obj; }