summaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
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/qthelper.cpp
parent3afc4528b32f4b716fbda6394fc74d1e226c36df (diff)
downloadsubsurface-e9debdf281a1a9661fb261df73446a8898be1d77.tar.gz
Add helper to parse duration text
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r--core/qthelper.cpp24
1 files changed, 24 insertions, 0 deletions
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;