From ccc2f1f0ff53ef613cc05f552ce6e69261ced51a Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 14 Mar 2010 21:23:46 +0000 Subject: [PATCH] Fix UTC to Localtime Error in GcRideFile The GcRideFile stores the ride start datetime in UTC, on write the datetime is correctly converted to UTC. This patch fixes the GcRideFile reader to convert in the oposite direction. Currently the code reads the UTC date as a local format date - as a result the convert to localtime call does nothing. --- src/GcRideFile.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/GcRideFile.cpp b/src/GcRideFile.cpp index ef5326148..5d6e5069b 100644 --- a/src/GcRideFile.cpp +++ b/src/GcRideFile.cpp @@ -54,8 +54,14 @@ GcFileReader::openRideFile(QFile &file, QStringList &errors) const QString value = attr.attribute("value"); if (key == "Device type") rideFile->setDeviceType(value); - if (key == "Start time") - rideFile->setStartTime(QDateTime::fromString(value, DATETIME_FORMAT).toLocalTime()); + if (key == "Start time") { + // by default QDateTime is localtime - the source however is UTC + QDateTime aslocal = QDateTime::fromString(value, DATETIME_FORMAT); + // construct in UTC so we can honour the conversion to localtime + QDateTime asUTC = QDateTime(aslocal.date(), aslocal.time(), Qt::UTC); + // now set in localtime + rideFile->setStartTime(asUTC.toLocalTime()); + } } QVector intervalStops; // used to set the interval number for each point