diff options
author | Robert C. Helling <helling@atdotde.de> | 2016-06-22 22:46:22 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-10 15:04:39 -0700 |
commit | 2c715542fd4fae6c2313c55d8c370689ff7dd931 (patch) | |
tree | 773aa73015d13ddc40402aa3f8ee6e5820b03c97 /desktop-widgets/simplewidgets.cpp | |
parent | bd40ef7f424604013e1fe1b5feea648ab6304b72 (diff) | |
download | subsurface-2c715542fd4fae6c2313c55d8c370689ff7dd931.tar.gz |
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 <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/simplewidgets.cpp')
-rw-r--r-- | desktop-widgets/simplewidgets.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index cbf31cb98..add4c80de 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -292,7 +292,6 @@ void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button) void ShiftImageTimesDialog::syncCameraClicked() { QPixmap picture; - QDateTime dcDateTime = QDateTime(); QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open image file"), DiveListView::lastUsedImageDir(), @@ -308,7 +307,7 @@ void ShiftImageTimesDialog::syncCameraClicked() ui.DCImage->setScene(scene); dcImageEpoch = picture_get_timestamp(fileNames.at(0).toUtf8().data()); - dcDateTime.setTime_t(dcImageEpoch - gettimezoneoffset(displayed_dive.when)); + QDateTime dcDateTime = QDateTime::fromTime_t(dcImageEpoch, Qt::UTC); ui.dcTime->setDateTime(dcDateTime); connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &))); } @@ -365,11 +364,10 @@ void ShiftImageTimesDialog::setOffset(time_t offset) void ShiftImageTimesDialog::updateInvalid() { timestamp_t timestamp; - QDateTime time; bool allValid = true; ui.warningLabel->hide(); ui.invalidLabel->hide(); - time.setTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when)); + QDateTime time = QDateTime::fromTime_t(displayed_dive.when, Qt::UTC); ui.invalidLabel->setText("Dive:" + time.toString() + "\n"); Q_FOREACH (const QString &fileName, fileNames) { @@ -378,7 +376,7 @@ void ShiftImageTimesDialog::updateInvalid() // We've found invalid image timestamp = picture_get_timestamp(fileName.toUtf8().data()); - time.setTime_t(timestamp + m_amount - gettimezoneoffset(displayed_dive.when)); + time.setTime_t(timestamp + m_amount); ui.invalidLabel->setText(ui.invalidLabel->text() + fileName + " " + time.toString() + "\n"); allValid = false; } |