diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-05-22 18:02:15 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-22 12:31:06 -0700 |
commit | f63485b444bd8469d24c70f64f3097bed239c7a8 (patch) | |
tree | 4960697b8efbe14846c1180160e224d1d903d3b2 /qt-models/divetripmodel.cpp | |
parent | 2ba2ea934aac45c6d8b3c6db920776fb2b29cc66 (diff) | |
download | subsurface-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 'qt-models/divetripmodel.cpp')
-rw-r--r-- | qt-models/divetripmodel.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index a153b31c7..a48c827dd 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -63,7 +63,7 @@ QString DiveTripModelBase::tripShortDate(const dive_trip *trip) { if (!trip) return QString(); - QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(trip), Qt::UTC); + QDateTime firstTime = timestampToDateTime(trip_date(trip)); QString firstMonth = firstTime.toString("MMM"); return QStringLiteral("%1\n'%2").arg(firstMonth,firstTime.toString("yy")); } @@ -79,10 +79,10 @@ QString DiveTripModelBase::tripTitle(const dive_trip *trip) if (title.isEmpty()) { // so use the date range - QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(trip), Qt::UTC); + QDateTime firstTime = timestampToDateTime(trip_date(trip)); QString firstMonth = firstTime.toString("MMM"); QString firstYear = firstTime.toString("yyyy"); - QDateTime lastTime = QDateTime::fromMSecsSinceEpoch(1000*trip->dives.dives[0]->when, Qt::UTC); + QDateTime lastTime = timestampToDateTime(trip->dives.dives[0]->when); QString lastMonth = lastTime.toString("MMM"); QString lastYear = lastTime.toString("yyyy"); if (lastMonth == firstMonth && lastYear == firstYear) @@ -201,8 +201,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) // variable in the QtQuick list view. That has to be a string because it will try // to do locale-aware sorting. And amazingly this can't be changed. case MobileListModel::DateTimeRole: { - QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000 * d->when, Qt::UTC); - localTime.setTimeSpec(Qt::UTC); + QDateTime localTime = timestampToDateTime(d->when); return QStringLiteral("%1 %2").arg(localTime.date().toString(prefs.date_format_short), localTime.time().toString(prefs.time_format)); } |