diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-05-22 18:53:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-22 12:31:06 -0700 |
commit | 8f80129bac29227a03c35940af9d197ef0fa6398 (patch) | |
tree | 40cd682efb11880af5410aab700dcd9d8bacbe72 /core | |
parent | e33e420ef3e5139015504ef49215721e99850f2b (diff) | |
download | subsurface-8f80129bac29227a03c35940af9d197ef0fa6398.tar.gz |
cleanup: create common QDateTime -> timestamp conversion function
In analogy to the timestamp -> QDateTime conversion, create a
common function.
1) For symmetry with the opposite conversion.
2) To remove numerous inconsistencies.
3) To remove use of the deprecated QDateTime::toTime_t() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/gpslocation.cpp | 4 | ||||
-rw-r--r-- | core/metadata.cpp | 8 | ||||
-rw-r--r-- | core/qthelper.cpp | 5 | ||||
-rw-r--r-- | core/qthelper.h | 1 |
4 files changed, 12 insertions, 6 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index ebd5b1950..cc11fa15e 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -169,7 +169,7 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) // if we are waiting for a position update or // if we have no record stored or if at least the configured minimum // time has passed or we moved at least the configured minimum distance - int64_t delta = (int64_t)pos.timestamp().toTime_t() + gettimezoneoffset() - lastTime; + int64_t delta = dateTimeToTimestamp(pos.timestamp()) + gettimezoneoffset() - lastTime; if (!nr || waitingForPosition || delta > prefs.time_threshold || lastCoord.distanceTo(pos.coordinate()) > prefs.distance_threshold) { QString msg = QStringLiteral("received new position %1 after delta %2 threshold %3 (now %4 last %5)"); @@ -177,7 +177,7 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) waitingForPosition = false; acquiredPosition(); gpsTracker gt; - gt.when = pos.timestamp().toTime_t(); + gt.when = dateTimeToTimestamp(pos.timestamp()); gt.when += gettimezoneoffset(gt.when); gt.location = create_location(pos.coordinate().latitude(), pos.coordinate().longitude()); addFixToStorage(gt); diff --git a/core/metadata.cpp b/core/metadata.cpp index 8692ea30f..e7cc0a08b 100644 --- a/core/metadata.cpp +++ b/core/metadata.cpp @@ -271,7 +271,7 @@ static bool parseDate(const QString &s_in, timestamp_t ×tamp) if (datetime.isValid()) { // Not knowing any better, we suppose that time is give in UTC datetime.setTimeSpec(Qt::UTC); - timestamp = datetime.toMSecsSinceEpoch() / 1000; + timestamp = dateTimeToTimestamp(datetime); return true; } @@ -312,7 +312,7 @@ static bool parseDate(const QString &s_in, timestamp_t ×tamp) // Not knowing any better, we suppose that time is give in UTC datetime = QDateTime(date, time, Qt::UTC); if (datetime.isValid()) { - timestamp = datetime.toMSecsSinceEpoch() / 1000; + timestamp = dateTimeToTimestamp(datetime); return true; } @@ -542,9 +542,9 @@ extern "C" mediatype_t get_metadata(const char *filename_in, metadata *data) // have a standard way of storing this datum), use the file creation date of the file. if (data->timestamp == 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) - data->timestamp = QFileInfo(filename).birthTime().toMSecsSinceEpoch() / 1000; + data->timestamp = dateTimeToTimestamp(QFileInfo(filename).birthTime()); #else - data->timestamp = QFileInfo(filename).created().toMSecsSinceEpoch() / 1000; + data->timestamp = dateTimeToTimestamp(QFileInfo(filename).created()); #endif return res; } diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 3b87a33a7..1ae788966 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -709,6 +709,11 @@ QDateTime timestampToDateTime(timestamp_t when) return QDateTime::fromMSecsSinceEpoch(1000 * when, Qt::UTC); } +timestamp_t dateTimeToTimestamp(const QDateTime &t) +{ + return t.toSecsSinceEpoch(); +} + QString render_seconds_to_string(int seconds) { if (seconds % 60 == 0) diff --git a/core/qthelper.h b/core/qthelper.h index b0cab8b15..1367a5007 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -63,6 +63,7 @@ QString getPrintingTemplatePathUser(); QString getPrintingTemplatePathBundle(); int gettimezoneoffset(timestamp_t when = 0); QDateTime timestampToDateTime(timestamp_t when); +timestamp_t dateTimeToTimestamp(const QDateTime &t); int parseDurationToSeconds(const QString &text); int parseLengthToMm(const QString &text); int parseTemperatureToMkelvin(const QString &text); |