From eb38a641490752578e3dddc7b7959cfd52e0be74 Mon Sep 17 00:00:00 2001 From: Oliver Schwaneberg Date: Sun, 4 Feb 2018 20:07:32 +0100 Subject: Do not remove seconds from duration input field This change deals with issue #554. If you enter a dive duration manually, the cell renderer cuts the seconds away when the changes are saved. I added the helper "render_seconds_to_string" as a counterpart to "parseDurationToSeconds". The helper keeps the seconds, if not null. The rendering of the cell is done at two places in the code, so I think it is cleaner to add a dedicated method for it. Signed-off-by: Oliver Schwaneberg --- core/helpers.h | 1 + core/qthelper.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'core') diff --git a/core/helpers.h b/core/helpers.h index 06c1c8527..57be623c5 100644 --- a/core/helpers.h +++ b/core/helpers.h @@ -36,6 +36,7 @@ int parseWeightToGrams(const QString &text); int parsePressureToMbar(const QString &text); int parseGasMixO2(const QString &text); int parseGasMixHE(const QString &text); +QString render_seconds_to_string(int seconds); QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = QObject::tr("sec"), QString separator = ":", bool isFreeDive = false); QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4); QString get_dive_date_string(timestamp_t when); diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 262399a5f..03dd56637 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -743,6 +743,14 @@ int gettimezoneoffset(timestamp_t when) return dt2.secsTo(dt1); } +QString render_seconds_to_string(int seconds) +{ + if (seconds % 60 == 0) + return QDateTime::fromTime_t(seconds).toUTC().toString("h:mm"); + else + return QDateTime::fromTime_t(seconds).toUTC().toString("h:mm:ss"); +} + int parseDurationToSeconds(const QString &text) { int secs; -- cgit v1.2.3-70-g09d2