mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 22:46:16 +00:00
Add helper to parse duration text
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3afc4528b3
commit
e9debdf281
2 changed files with 25 additions and 0 deletions
|
@ -28,6 +28,7 @@ QString getPrintingTemplatePathBundle();
|
||||||
void copyPath(QString src, QString dst);
|
void copyPath(QString src, QString dst);
|
||||||
extern const QString get_dc_nickname(const char *model, uint32_t deviceid);
|
extern const QString get_dc_nickname(const char *model, uint32_t deviceid);
|
||||||
int gettimezoneoffset(timestamp_t when = 0);
|
int gettimezoneoffset(timestamp_t when = 0);
|
||||||
|
int parseDurationToSeconds(const QString &text);
|
||||||
int parseLengthToMm(const QString &text);
|
int parseLengthToMm(const QString &text);
|
||||||
int parseTemperatureToMkelvin(const QString &text);
|
int parseTemperatureToMkelvin(const QString &text);
|
||||||
int parseWeightToGrams(const QString &text);
|
int parseWeightToGrams(const QString &text);
|
||||||
|
|
|
@ -755,6 +755,30 @@ int gettimezoneoffset(timestamp_t when)
|
||||||
return dt2.secsTo(dt1);
|
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 parseLengthToMm(const QString &text)
|
||||||
{
|
{
|
||||||
int mm;
|
int mm;
|
||||||
|
|
Loading…
Add table
Reference in a new issue