diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-05-06 17:43:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-06 17:43:32 -0700 |
commit | 92d24a2912d1e9302b86d74a13a9bc124e7b380c (patch) | |
tree | 230a01f62aa4111cb7b6b459fddad66fd9c22446 /core | |
parent | 876b479d695acda652e7b6c81c6b899946d42a85 (diff) | |
download | subsurface-92d24a2912d1e9302b86d74a13a9bc124e7b380c.tar.gz |
Consistently show dive duration based on preferences
We now respect the settings in the preferences and also only show
the duration as minutes and seconds if the dive is a free dive.
Fixes #361
Fixes #362
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/helpers.h | 2 | ||||
-rw-r--r-- | core/qthelper.cpp | 22 |
2 files changed, 14 insertions, 10 deletions
diff --git a/core/helpers.h b/core/helpers.h index d694be941..a6e152cbf 100644 --- a/core/helpers.h +++ b/core/helpers.h @@ -36,7 +36,7 @@ int parseWeightToGrams(const QString &text); int parsePressureToMbar(const QString &text); int parseGasMixO2(const QString &text); int parseGasMixHE(const QString &text); -QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText); +QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText = "", bool isFreeDive = false); QString get_dive_date_string(timestamp_t when); QString get_short_dive_date_string(timestamp_t when); bool is_same_day (timestamp_t trip_when, timestamp_t dive_when); diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 0cf37fffb..2ba358fc0 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -924,19 +924,23 @@ int parseGasMixHE(const QString &text) return he; } -QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText) +QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive) { - int hrs, mins; + int hrs, mins, fullmins, secs; mins = (when + 59) / 60; + fullmins = when / 60; + secs = when - 60 * fullmins; hrs = mins / 60; - mins -= hrs * 60; QString displayTime; - if (hrs) - displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(minutesText); - else - displayTime = QString("%1%2").arg(mins).arg(minutesText); - + if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) { + mins -= hrs * 60; + displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(hourText == ":" ? "" : minutesText); + } else if (isFreeDive) { + displayTime = QString("%1%2%3%4").arg(fullmins).arg(minutesText).arg(secs, 2, 10, QChar('0')).arg(secondsText); + } else { + displayTime = QString("%1%2").arg(mins).arg(hourText == ":" ? "" : minutesText); + } return displayTime; } @@ -964,7 +968,7 @@ extern "C" const char *get_current_date() { QDateTime ts(QDateTime::currentDateTime());; QString current_date; - + current_date = loc.toString(ts, QString(prefs.date_format_short)); return strdup(current_date.toUtf8().data()); |