From 6c7411c776597d46074247923137965e2216b732 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 7 Feb 2020 15:49:31 -0800 Subject: mobile/summary: use more intuitive time periods No one will ask you about your dives in the last seven months (and the existing code actually provided the past 210 days in that case). Instead do more intuitive periods. Last month, quarter, half year, year. Use Qt's ability to make sane date calculations easy. Signed-off-by: Dirk Hohndel --- qt-models/divesummarymodel.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'qt-models/divesummarymodel.cpp') diff --git a/qt-models/divesummarymodel.cpp b/qt-models/divesummarymodel.cpp index 739463246..1c192a573 100644 --- a/qt-models/divesummarymodel.cpp +++ b/qt-models/divesummarymodel.cpp @@ -242,12 +242,28 @@ void DiveSummaryModel::calc(int column, int period) if (column >= (int)results.size()) return; - QDateTime localTime; - - // Calculate Start of the 2 periods. - timestamp_t now, start; - now = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); - start = (period == 0) ? 0 : now - period * 30 * 24 * 60 * 60; + QDateTime currentTime = QDateTime::currentDateTime(); + QDateTime startTime = currentTime; + + // Calculate Start of the periods. + switch (period) { + case 0: // having startTime == currentTime is used as special case below + break; + case 1: startTime = currentTime.addMonths(-1); + break; + case 2: startTime = currentTime.addMonths(-3); + break; + case 3: startTime = currentTime.addMonths(-6); + break; + case 4: startTime = currentTime.addYears(-1); + break; + default: qWarning("DiveSummaryModel::calc called with invalid period"); + } + timestamp_t start; + if (startTime == currentTime) + start = 0; + else + start = startTime.toMSecsSinceEpoch() / 1000L + gettimezoneoffset(); // Loop over all dives and sum up data Stats stats = loopDives(start); -- cgit v1.2.3-70-g09d2