diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-07-29 10:58:35 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-07-29 13:01:46 -0700 |
commit | d262886a2dccccbc01413c05a302be9044433a76 (patch) | |
tree | 30a354fc658b8a69163608af845986c7a2577ae7 /qt-ui | |
parent | 9edee3477a1fa3945717512e591f30af9c3ca468 (diff) | |
download | subsurface-d262886a2dccccbc01413c05a302be9044433a76.tar.gz |
Fix time zone conversions
I know I tested this - no idea how I missed this.
Anyway, this was of course utterly bogus. Whenever we get a time from a
time_t into a Qt Date or Time datastructure, we need to adjust it by the
timezone offset as otherwise Qt will assume it's in local time and
helpfully change it to the wrong values for us.
See #655
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 7 | ||||
-rw-r--r-- | qt-ui/maintab.ui | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index bf108a9c1..871e9cc41 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -390,7 +390,10 @@ void MainTab::updateDiveInfo(bool clear) if (!clear) { updateGpsCoordinates(&displayed_dive); + // Subsurface always uses "local time" as in "whatever was the local time at the location" + // so all time stamps have no time zone information and are in UTC QDateTime localTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when)); + localTime.setTimeSpec(Qt::UTC); ui.dateEdit->setDate(localTime.date()); ui.timeEdit->setTime(localTime.time()); if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { @@ -930,7 +933,7 @@ void MainTab::on_dateEdit_dateChanged(const QDate &date) { if (editMode == IGNORE) return; - QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when); + QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when)); dateTime.setTimeSpec(Qt::UTC); dateTime.setDate(date); displayed_dive.when = dateTime.toTime_t(); @@ -941,7 +944,7 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time) { if (editMode == IGNORE) return; - QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when); + QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when)); dateTime.setTimeSpec(Qt::UTC); dateTime.setTime(time); displayed_dive.when = dateTime.toTime_t(); diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 2770801a2..ca58ab034 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -284,6 +284,9 @@ <verstretch>0</verstretch> </sizepolicy> </property> + <property name="timeSpec"> + <enum>Qt::UTC</enum> + </property> </widget> </item> <item row="2" column="0"> @@ -291,6 +294,9 @@ <property name="calendarPopup"> <bool>true</bool> </property> + <property name="timeSpec"> + <enum>Qt::UTC</enum> + </property> </widget> </item> <item row="1" column="0"> |