From 9d2449c5c302a67044f4a7d6802a38bafa477ecc Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 6 Jul 2020 14:37:39 -0700 Subject: mobile/location-service: fix timezone issue in GPS timestamps For some reason we suddenly started logging the GPS fixes in UTC instead of local time. Which caused the matching algorithm to fail (unless you happened to be diving in UTC). Unclear what broke this, but this seems like an easy enough fix, since the GPS fix being reported is by definition "right around now". So using gettimezoneoffset() with the current time seems "good enough". I don't know when gettimezoneoffset() with an argument got broken, TBH. Signed-off-by: Dirk Hohndel --- core/gpslocation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index cc11fa15e..2d63b42f5 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -158,6 +158,7 @@ QString GpsLocation::currentPosition() void GpsLocation::newPosition(QGeoPositionInfo pos) { int64_t lastTime = 0; + int64_t thisTime = dateTimeToTimestamp(pos.timestamp()) + gettimezoneoffset(); QGeoCoordinate lastCoord; int nr = m_trackers.count(); if (nr) { @@ -169,7 +170,7 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) // if we are waiting for a position update or // if we have no record stored or if at least the configured minimum // time has passed or we moved at least the configured minimum distance - int64_t delta = dateTimeToTimestamp(pos.timestamp()) + gettimezoneoffset() - lastTime; + int64_t delta = thisTime - lastTime; if (!nr || waitingForPosition || delta > prefs.time_threshold || lastCoord.distanceTo(pos.coordinate()) > prefs.distance_threshold) { QString msg = QStringLiteral("received new position %1 after delta %2 threshold %3 (now %4 last %5)"); @@ -177,12 +178,11 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) waitingForPosition = false; acquiredPosition(); gpsTracker gt; - gt.when = dateTimeToTimestamp(pos.timestamp()); - gt.when += gettimezoneoffset(gt.when); + gt.when = thisTime; gt.location = create_location(pos.coordinate().latitude(), pos.coordinate().longitude()); addFixToStorage(gt); gpsTracker gtNew = m_trackers.last(); - qDebug() << "newest fix is now at" << timestampToDateTime(gtNew.when - gettimezoneoffset(gtNew.when)).toString(); + qDebug() << "newest fix is now at" << timestampToDateTime(gtNew.when - gettimezoneoffset()).toString(); } } -- cgit v1.2.3-70-g09d2