summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-02-25 20:23:03 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-03-04 12:16:49 -0800
commite9debdf281a1a9661fb261df73446a8898be1d77 (patch)
tree9959abd47e0294bac6bfa5f899cc462346392da3 /core
parent3afc4528b32f4b716fbda6394fc74d1e226c36df (diff)
downloadsubsurface-e9debdf281a1a9661fb261df73446a8898be1d77.tar.gz
Add helper to parse duration text
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/helpers.h1
-rw-r--r--core/qthelper.cpp24
2 files changed, 25 insertions, 0 deletions
diff --git a/core/helpers.h b/core/helpers.h
index a4a903ea6..7acbeaff6 100644
--- a/core/helpers.h
+++ b/core/helpers.h
@@ -28,6 +28,7 @@ QString getPrintingTemplatePathBundle();
void copyPath(QString src, QString dst);
extern const QString get_dc_nickname(const char *model, uint32_t deviceid);
int gettimezoneoffset(timestamp_t when = 0);
+int parseDurationToSeconds(const QString &text);
int parseLengthToMm(const QString &text);
int parseTemperatureToMkelvin(const QString &text);
int parseWeightToGrams(const QString &text);
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index eb68fe206..e2615ec31 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -755,6 +755,30 @@ int gettimezoneoffset(timestamp_t when)
return dt2.secsTo(dt1);
}
+int parseDurationToSeconds(const QString &text)
+{
+ int secs;
+ QString numOnly = text;
+ QString hours, minutes, seconds;
+ numOnly.replace(",", ".").remove(QRegExp("[^-0-9.:]"));
+ if (numOnly.isEmpty())
+ return 0;
+ if (numOnly.contains(':')) {
+ hours = numOnly.left(numOnly.indexOf(':'));
+ minutes = numOnly.right(numOnly.length() - hours.length() - 1);
+ if (minutes.contains(':')) {
+ numOnly = minutes;
+ minutes = numOnly.left(numOnly.indexOf(':'));
+ seconds = numOnly.right(numOnly.length() - minutes.length() - 1);
+ }
+ } else {
+ hours = "0";
+ minutes = numOnly;
+ }
+ secs = hours.toDouble() * 3600 + minutes.toDouble() * 60 + seconds.toDouble();
+ return secs;
+}
+
int parseLengthToMm(const QString &text)
{
int mm;