mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:13:23 +00:00
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>
This commit is contained in:
parent
84166a4ee7
commit
56ed3f1c61
4 changed files with 13 additions and 14 deletions
|
@ -950,7 +950,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
utc_mkdate(when, &tm);
|
utc_mkdate(when, &tm);
|
||||||
QDateTime localTime = QDateTime::fromTime_t(when);
|
QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*when,Qt::UTC);
|
||||||
localTime.setTimeSpec(Qt::UTC);
|
localTime.setTimeSpec(Qt::UTC);
|
||||||
QString ret ;
|
QString ret ;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ int DiveObjectHelper::id() const
|
||||||
|
|
||||||
QString DiveObjectHelper::date() 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);
|
localTime.setTimeSpec(Qt::UTC);
|
||||||
return localTime.date().toString(prefs.date_format);
|
return localTime.date().toString(prefs.date_format);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ timestamp_t DiveObjectHelper::timestamp() const
|
||||||
|
|
||||||
QString DiveObjectHelper::time() 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);
|
localTime.setTimeSpec(Qt::UTC);
|
||||||
return localTime.time().toString(prefs.time_format);
|
return localTime.time().toString(prefs.time_format);
|
||||||
}
|
}
|
||||||
|
@ -288,13 +288,12 @@ QString DiveObjectHelper::tripMeta() const
|
||||||
QString title(dt->location);
|
QString title(dt->location);
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
// so use the date range
|
// so use the date range
|
||||||
timestamp_t firstTime = dt->when - gettimezoneoffset(dt->when);
|
QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*dt->when, Qt::UTC);
|
||||||
QString firstMonth = QDateTime::fromTime_t(firstTime).toString("MMM");
|
QString firstMonth = firstTime.toString("MMM");
|
||||||
QString firstYear = QDateTime::fromTime_t(firstTime).toString("yyyy");
|
QString firstYear = firstTime.toString("yyyy");
|
||||||
struct dive *lastDive = dt->dives;
|
QDateTime lastTime = QDateTime::fromMSecsSinceEpoch(1000*dt->dives->when, Qt::UTC);
|
||||||
timestamp_t lastTime = lastDive->when - gettimezoneoffset(lastDive->when);
|
QString lastMonth = lastTime.toString("MMM");
|
||||||
QString lastMonth = QDateTime::fromTime_t(lastTime).toString("MMM");
|
QString lastYear = lastTime.toString("yyyy");
|
||||||
QString lastYear = QDateTime::fromTime_t(lastTime).toString("yyyy");
|
|
||||||
if (lastMonth == firstMonth && lastYear == firstYear)
|
if (lastMonth == firstMonth && lastYear == firstYear)
|
||||||
title = firstMonth + " " + firstYear;
|
title = firstMonth + " " + firstYear;
|
||||||
else if (lastMonth != firstMonth && lastYear == firstYear)
|
else if (lastMonth != firstMonth && lastYear == firstYear)
|
||||||
|
|
|
@ -493,7 +493,7 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
|
|
||||||
// Subsurface always uses "local time" as in "whatever was the local time at the location"
|
// 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
|
// so all time stamps have no time zone information and are in UTC
|
||||||
QDateTime localTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when));
|
QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
|
||||||
localTime.setTimeSpec(Qt::UTC);
|
localTime.setTimeSpec(Qt::UTC);
|
||||||
ui.dateEdit->setDate(localTime.date());
|
ui.dateEdit->setDate(localTime.date());
|
||||||
ui.timeEdit->setTime(localTime.time());
|
ui.timeEdit->setTime(localTime.time());
|
||||||
|
@ -1284,7 +1284,7 @@ void MainTab::on_dateEdit_dateChanged(const QDate &date)
|
||||||
if (editMode == IGNORE || acceptingEdit == true)
|
if (editMode == IGNORE || acceptingEdit == true)
|
||||||
return;
|
return;
|
||||||
markChangedWidget(ui.dateEdit);
|
markChangedWidget(ui.dateEdit);
|
||||||
QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when));
|
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
|
||||||
dateTime.setTimeSpec(Qt::UTC);
|
dateTime.setTimeSpec(Qt::UTC);
|
||||||
dateTime.setDate(date);
|
dateTime.setDate(date);
|
||||||
DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
|
DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
|
||||||
|
@ -1296,7 +1296,7 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time)
|
||||||
if (editMode == IGNORE || acceptingEdit == true)
|
if (editMode == IGNORE || acceptingEdit == true)
|
||||||
return;
|
return;
|
||||||
markChangedWidget(ui.timeEdit);
|
markChangedWidget(ui.timeEdit);
|
||||||
QDateTime dateTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when));
|
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
|
||||||
dateTime.setTimeSpec(Qt::UTC);
|
dateTime.setTimeSpec(Qt::UTC);
|
||||||
dateTime.setTime(time);
|
dateTime.setTime(time);
|
||||||
DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
|
DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<dives>
|
<dives>
|
||||||
<program name='subsurface' version='1'></program>
|
<program name='subsurface' version='1'></program>
|
||||||
<dive number='0' date='2011-01-01' time='07:00:00' duration='30:00 min'>
|
<dive number='0' date='1968-01-01' time='07:00:00' duration='30:00 min'>
|
||||||
<depth max='30.00 m' mean='15.00 m' />
|
<depth max='30.00 m' mean='15.00 m' />
|
||||||
</dive>
|
</dive>
|
||||||
</dives>
|
</dives>
|
||||||
|
|
Loading…
Add table
Reference in a new issue