summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/gpslocation.cpp4
-rw-r--r--core/metadata.cpp8
-rw-r--r--core/qthelper.cpp5
-rw-r--r--core/qthelper.h1
-rw-r--r--desktop-widgets/simplewidgets.cpp2
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp2
-rw-r--r--mobile-widgets/qmlmanager.cpp2
-rw-r--r--qt-models/diveplannermodel.cpp6
-rw-r--r--qt-models/divesummarymodel.cpp2
9 files changed, 19 insertions, 13 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 &timestamp)
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 &timestamp)
// 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);
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index b6244c826..ba3dc67ee 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -279,7 +279,7 @@ void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime)
if (!dcImageEpoch)
return;
newtime.setTimeSpec(Qt::UTC);
- setOffset(newtime.toTime_t() - dcImageEpoch);
+ setOffset(dateTimeToTimestamp(newtime) - dcImageEpoch);
}
void ShiftImageTimesDialog::matchAllImagesToggled(bool state)
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 81c56a486..978b22692 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -598,7 +598,7 @@ void MainTab::on_depth_editingFinished()
// all dives are shifted by an offset.
static void shiftTime(QDateTime &dateTime)
{
- timestamp_t when = dateTime.toTime_t();
+ timestamp_t when = dateTimeToTimestamp(dateTime);
if (current_dive && current_dive->when != when) {
timestamp_t offset = when - current_dive->when;
Command::shiftTime(getDiveSelection(), (int)offset);
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 36394364b..82cc5309b 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -908,7 +908,7 @@ parsed:
// add a hundred years.
if (newDate.addYears(100) < QDateTime::currentDateTime().addYears(1))
newDate = newDate.addYears(100);
- d->dc.when = d->when = newDate.toMSecsSinceEpoch() / 1000;
+ d->dc.when = d->when = dateTimeToTimestamp(newDate);
return true;
}
appendTextToLog("none of our parsing attempts worked for the date string");
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index d0b919a61..ebcbeb51e 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -85,7 +85,7 @@ void DivePlannerPointsModel::setupStartTime()
if (dive_table.nr) {
struct dive *d = get_dive(dive_table.nr - 1);
time_t ends = dive_endtime(d);
- time_t diff = ends - startTime.toTime_t();
+ time_t diff = ends - dateTimeToTimestamp(startTime);
if (diff > 0) {
startTime = startTime.addSecs(diff + 3600);
}
@@ -700,7 +700,7 @@ void DivePlannerPointsModel::setSurfaceSegment(int duration)
void DivePlannerPointsModel::setStartDate(const QDate &date)
{
startTime.setDate(date);
- diveplan.when = startTime.toTime_t();
+ diveplan.when = dateTimeToTimestamp(startTime);
displayed_dive.when = diveplan.when;
emitDataChanged();
}
@@ -708,7 +708,7 @@ void DivePlannerPointsModel::setStartDate(const QDate &date)
void DivePlannerPointsModel::setStartTime(const QTime &t)
{
startTime.setTime(t);
- diveplan.when = startTime.toTime_t();
+ diveplan.when = dateTimeToTimestamp(startTime);
displayed_dive.when = diveplan.when;
emitDataChanged();
}
diff --git a/qt-models/divesummarymodel.cpp b/qt-models/divesummarymodel.cpp
index f12a345e5..d187f2b58 100644
--- a/qt-models/divesummarymodel.cpp
+++ b/qt-models/divesummarymodel.cpp
@@ -263,7 +263,7 @@ void DiveSummaryModel::calc(int column, int period)
if (startTime == currentTime)
start = 0;
else
- start = startTime.toMSecsSinceEpoch() / 1000L + gettimezoneoffset();
+ start = dateTimeToTimestamp(startTime) + gettimezoneoffset();
// Loop over all dives and sum up data
Stats stats = loopDives(start);