summaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-05-22 18:02:15 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-22 12:31:06 -0700
commitf63485b444bd8469d24c70f64f3097bed239c7a8 (patch)
tree4960697b8efbe14846c1180160e224d1d903d3b2 /core/qthelper.cpp
parent2ba2ea934aac45c6d8b3c6db920776fb2b29cc66 (diff)
downloadsubsurface-f63485b444bd8469d24c70f64f3097bed239c7a8.tar.gz
cleanup: move timestampToDateTime() to qthelper.cpp
Move this function from maintab.cpp to qthelper.cpp. Since the functionality was used in numerous places, use the helper function there as well. This removes a number of inconsistencies. For example, sometime setTimeSpec(Qt::UTC) was called, even though the QDateTime object was already created with that time spec. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r--core/qthelper.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index e1329ca26..561dd9213 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -696,12 +696,19 @@ int gettimezoneoffset(timestamp_t when)
if (when == 0)
dt1 = QDateTime::currentDateTime();
else
- dt1 = QDateTime::fromMSecsSinceEpoch(when * 1000);
+ dt1 = timestampToDateTime(when);
dt2 = dt1.toUTC();
dt1.setTimeSpec(Qt::UTC);
return dt2.secsTo(dt1);
}
+QDateTime timestampToDateTime(timestamp_t when)
+{
+ // 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
+ return QDateTime::fromMSecsSinceEpoch(1000 * when, Qt::UTC);
+}
+
QString render_seconds_to_string(int seconds)
{
if (seconds % 60 == 0)
@@ -984,8 +991,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday)
{
struct tm tm;
utc_mkdate(when, &tm);
- QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*when,Qt::UTC);
- localTime.setTimeSpec(Qt::UTC);
+ QDateTime localTime = timestampToDateTime(when);
QString suffix = " " + gettextFromC::tr("(%n dive(s))", "", nr);
if (getday)