[PATCH] Avoid using manual timezone offsets.

Michael Andreen harv at ruin.nu
Fri Nov 29 23:35:15 UTC 2013


Since some early bird thought it was a good idea to force the rest of us
to get up early by changing our clocks during summer, we can not use the
currentDateTime() to determine the timezone offset for all dives.

Instead, we just pretend that everything is in UTC and avoid doing the
offset calculations.

If only that early bird knew that if clocks stayed consistent throughout
the year then I could be asleep instead of fixing this in the middle of
the night..

Signed-off-by: Michael Andreen <harv at ruin.nu>
---
I'm not entirely sure why this manages to trick the QDateTimeEdit, but it seems to work.

Did I mention that I don't like daylight saving time? ;)
 qt-ui/maintab.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 0e1e522..a5665dc 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -213,7 +213,7 @@ void MainTab::enableEdition(EditMode newEditMode)
 			notesBackup[mydive].coordinates  = ui.coordinates->text();
 			notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true);
 			notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true);
-			notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when - gettimezoneoffset()).toString();
+			notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when).toUTC().toString();
 			char buf[1024];
 			taglist_get_tagstring(mydive->tag_list, buf, 1024);
 			notesBackup[mydive].tags = QString(buf);
@@ -334,7 +334,7 @@ void MainTab::updateDiveInfo(int dive)
 	UPDATE_TEMP(d, watertemp);
 	if (d) {
 		updateGpsCoordinates(d);
-		ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when - gettimezoneoffset()));
+		ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when).toUTC());
 		if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
 			setTabText(0, tr("Trip Notes"));
 			// only use trip relevant fields
@@ -771,7 +771,9 @@ void MainTab::on_watertemp_textChanged(const QString& text)
 
 void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime)
 {
-	EDIT_SELECTED_DIVES( mydive->when = datetime.toTime_t() + gettimezoneoffset() );
+	QDateTime dateTimeUtc(datetime);
+	dateTimeUtc.setTimeSpec(Qt::UTC);
+	EDIT_SELECTED_DIVES( mydive->when = dateTimeUtc.toTime_t() );
 	markChangedWidget(ui.dateTimeEdit);
 }
 
-- 
1.8.3.2




More information about the subsurface mailing list