From 2c715542fd4fae6c2313c55d8c370689ff7dd931 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Wed, 22 Jun 2016 22:46:22 +0200 Subject: Unify handling of QDateTime time zone information Subsurface uses "local time" which in particular means we never display time zone information to the user. The user (and our file format) only sees times like 5pm or 17:00. A better name than local time (which could mean "local at the dive spot) would be "watch time", the time displayed by the diver's watch when she entered the water. Internally, we store times as time_t, seconds since Jan 1 1970 0:00 UTC. Our convention for conversion between 5pm and time_t as always been to treat 5pm as if it were UTC. Then confusion arose since Qt's QDateTime (which is tied to UI elements like QTimeEdit and similar) is time zone aware and by default assumes the system time zone. So when we set a QDateTime to 5pm and then later convert it to time_t we have to take care about the difference between UTC and the system time zone. This patch unifies our solution to this problem: With it, we set all QDateTime's time zone to UTC. This means we don't have to correct for a time zone anymore when converting to time_t (note, however, the signedness issue: Qt's idea of time_t is broken since it assumes it to be unsigned thus not allowing for dates before 1970. Better use the millisecont variants). We only need to be careful about time zones when using the current time. With this convention, when assigning the current time to a QDateTime, we need to shift for the time zone since its value in UTC should actually be the watch time of the user who is most likely used to the system time zone. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- qt-models/diveplannermodel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qt-models') diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 03cc90e06..425d8bc1a 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -353,6 +353,7 @@ DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTable tempGFLow(100) { memset(&diveplan, 0, sizeof(diveplan)); + startTime.setTimeSpec(Qt::UTC); } DivePlannerPointsModel *DivePlannerPointsModel::instance() @@ -540,7 +541,7 @@ void DivePlannerPointsModel::setStartDate(const QDate &date) void DivePlannerPointsModel::setStartTime(const QTime &t) { startTime.setTime(t); - diveplan.when = startTime.toTime_t(); + diveplan.when = startTime.toTime_t(); displayed_dive.when = diveplan.when; emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); } -- cgit v1.2.3-70-g09d2