From 2886104b1dca5e33ddb49ca126466d57d7cab7f9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 17 Mar 2022 14:37:20 -0700 Subject: [PATCH] mobile: allow date only when adding/editing dives Apparently some people try to manually enter older dives where they don't have data about the dive time and therefore want to only capture the dive date. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 33741a95a..eb382a002 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -965,6 +965,35 @@ bool QMLManager::checkDate(struct dive *d, QString date) if (newDate.isValid()) goto parsed; } + // if everything else failed - maybe the user is entering dives where they + // don't recall the time? So let's try date only patterns... + QRegularExpression usDateOnly("\\d+/\\d+/\\d+"); + if (date.contains(usDateOnly)) { + newDate = QDateTime::fromString(date, "M/d/yy"); + if (newDate.isValid()) + goto parsed; + newDate = QDateTime::fromString(date, "M/d/yyyy"); + if (newDate.isValid()) + goto parsed; + } + QRegularExpression leDateOnly("\\d+\\.\\d+\\.\\d+"); + if (date.contains(usDateOnly)) { + newDate = QDateTime::fromString(date, "d.M.yy"); + if (newDate.isValid()) + goto parsed; + newDate = QDateTime::fromString(date, "d.M.yyyy"); + if (newDate.isValid()) + goto parsed; + } + QRegularExpression isoDateOnly("\\d+-\\d+-\\d+"); + if (date.contains(usDateOnly)) { + newDate = QDateTime::fromString(date, "yy-M-d"); + if (newDate.isValid()) + goto parsed; + newDate = QDateTime::fromString(date, "yyyy-M-d"); + if (newDate.isValid()) + goto parsed; + } } parsed: if (newDate.isValid()) {