summaryrefslogtreecommitdiffstats
path: root/qt-mobile/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-03-10 18:36:46 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-03-10 18:36:46 -0800
commit969ca3d9ea4e2a9ccc959750957c3fc57f7bfb2b (patch)
tree957d3ba4b772cd731a2c24b9c82e1dc51ecd1ac9 /qt-mobile/qmlmanager.cpp
parent3be6b128fdda4cd9ed845b467001c4862dd7d0c1 (diff)
downloadsubsurface-969ca3d9ea4e2a9ccc959750957c3fc57f7bfb2b.tar.gz
QML UI: if the date entered doesn't match the format, try harder
This implements a bunch of standard date and time formats, hoping that what the user entered matches one of them. I guess in the end we need to find decent calendar/clock based widgets to enter the time and avoid the whole parsing hassle. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile/qmlmanager.cpp')
-rw-r--r--qt-mobile/qmlmanager.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index f0e6dcca4..a4759be43 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -6,6 +6,7 @@
#include <QAuthenticator>
#include <QDesktopServices>
#include <QTextDocument>
+#include <QRegularExpression>
#include "qt-models/divelistmodel.h"
#include <gpslistmodel.h>
@@ -416,6 +417,76 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
date.replace(drop, "");
}
newDate = QDateTime::fromString(date, format);
+ if (!newDate.isValid()) {
+ qDebug() << "unable to parse date" << date << "with the given format" << format;
+ QRegularExpression isoDate("\\d+-\\d+-\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(isoDate)) {
+ newDate = QDateTime::fromString(date, "yyyy-M-d h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "yy-M-d h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression isoDateNoSecs("\\d+-\\d+-\\d+[^\\d]+\\d+");
+ if (date.contains(isoDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "yyyy-M-d h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "yy-M-d h:m");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression usDate("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+:\\d+");
+ if (date.contains(usDate)) {
+ newDate = QDateTime::fromString(date, "M/d/yyyy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "M/d/yy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:m:sap");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:m:sap");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression usDateNoSecs("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(usDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "M/d/yyyy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "M/d/yy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:map");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:map");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression leDate("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+:\\d+");
+ if (date.contains(leDate)) {
+ newDate = QDateTime::fromString(date, "d.M.yyyy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "d.M.yy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression leDateNoSecs("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(leDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "d.M.yyyy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "d.M.yy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ }
+parsed:
if (newDate.isValid()) {
// stupid Qt... two digit years are always 19xx - WTF???
// so if adding a hundred years gets you into something before a year from now...
@@ -423,6 +494,8 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
if (newDate.addYears(100) < QDateTime::currentDateTime().addYears(1))
newDate = newDate.addYears(100);
d->dc.when = d->when = newDate.toMSecsSinceEpoch() / 1000 + gettimezoneoffset(newDate.toMSecsSinceEpoch() / 1000);
+ } else {
+ qDebug() << "none of our parsing attempts worked for the date string";
}
}
struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);