QML UI: correctly parse manually edited date

We need to set the timeSpec after the QDateTime was parsed,
otherwise it gets converted to localtime again.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-04-15 18:51:03 -07:00
parent f2d88619c5
commit 03b2b854bf

View file

@ -589,7 +589,6 @@ bool QMLManager::checkDate(DiveObjectHelper *myDive, struct dive * d, QString da
QString oldDate = myDive->date() + " " + myDive->time();
if (date != oldDate) {
QDateTime newDate;
newDate.setTimeSpec(Qt::UTC);
// what a pain - Qt will not parse dates if the day of the week is incorrect
// so if the user changed the date but didn't update the day of the week (most likely behavior, actually),
// we need to make sure we don't try to parse that
@ -603,7 +602,9 @@ bool QMLManager::checkDate(DiveObjectHelper *myDive, struct dive * d, QString da
format.replace(dateFormatToDrop, "");
date.replace(drop, "");
}
// set date from string and make sure it's treated as UTC (like all our time stamps)
newDate = QDateTime::fromString(date, format);
newDate.setTimeSpec(Qt::UTC);
if (!newDate.isValid()) {
qDebug() << "unable to parse date" << date << "with the given format" << format;
QRegularExpression isoDate("\\d+-\\d+-\\d+[^\\d]+\\d+:\\d+");