summaryrefslogtreecommitdiffstats
path: root/core/subsurface-qt/DiveObjectHelper.cpp
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2016-04-28 16:31:37 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-29 09:07:41 -0700
commit56ed3f1c6119b9ac86f602455d54318623640056 (patch)
tree0c342158ea4c2d2443139361deba786fa1b01bab /core/subsurface-qt/DiveObjectHelper.cpp
parent84166a4ee77502bdb4a981bc5404a1a970c579cc (diff)
downloadsubsurface-56ed3f1c6119b9ac86f602455d54318623640056.tar.gz
Fix Qt date interfaces for times before 1970
This seems to work around the crazy QDateTime::fromTime_t() problem in Qt. It is *very* lightly tested. In fact, the only test is that "test0.xml" change that is part of this patch. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/subsurface-qt/DiveObjectHelper.cpp')
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index dc22e59a2..e2847f7c9 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -73,7 +73,7 @@ int DiveObjectHelper::id() const
QString DiveObjectHelper::date() const
{
- QDateTime localTime = QDateTime::fromTime_t(m_dive->when - gettimezoneoffset(m_dive->when));
+ QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*m_dive->when, Qt::UTC);
localTime.setTimeSpec(Qt::UTC);
return localTime.date().toString(prefs.date_format);
}
@@ -85,7 +85,7 @@ timestamp_t DiveObjectHelper::timestamp() const
QString DiveObjectHelper::time() const
{
- QDateTime localTime = QDateTime::fromTime_t(m_dive->when - gettimezoneoffset(m_dive->when));
+ QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*m_dive->when, Qt::UTC);
localTime.setTimeSpec(Qt::UTC);
return localTime.time().toString(prefs.time_format);
}
@@ -288,13 +288,12 @@ QString DiveObjectHelper::tripMeta() const
QString title(dt->location);
if (title.isEmpty()) {
// so use the date range
- timestamp_t firstTime = dt->when - gettimezoneoffset(dt->when);
- QString firstMonth = QDateTime::fromTime_t(firstTime).toString("MMM");
- QString firstYear = QDateTime::fromTime_t(firstTime).toString("yyyy");
- struct dive *lastDive = dt->dives;
- timestamp_t lastTime = lastDive->when - gettimezoneoffset(lastDive->when);
- QString lastMonth = QDateTime::fromTime_t(lastTime).toString("MMM");
- QString lastYear = QDateTime::fromTime_t(lastTime).toString("yyyy");
+ QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*dt->when, Qt::UTC);
+ QString firstMonth = firstTime.toString("MMM");
+ QString firstYear = firstTime.toString("yyyy");
+ QDateTime lastTime = QDateTime::fromMSecsSinceEpoch(1000*dt->dives->when, Qt::UTC);
+ QString lastMonth = lastTime.toString("MMM");
+ QString lastYear = lastTime.toString("yyyy");
if (lastMonth == firstMonth && lastYear == firstYear)
title = firstMonth + " " + firstYear;
else if (lastMonth != firstMonth && lastYear == firstYear)