diff --git a/core/divelogexportlogic.cpp b/core/divelogexportlogic.cpp index 7323eefbb..7e7e0675a 100644 --- a/core/divelogexportlogic.cpp +++ b/core/divelogexportlogic.cpp @@ -9,6 +9,7 @@ #include "qthelper.h" #include "units.h" #include "statistics.h" +#include "string-format.h" #include "save-html.h" static void file_copy_and_overwrite(const QString &fileName, const QString &newName) @@ -93,9 +94,9 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\","; out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\","; - out << "\"AVERAGE_TIME\":\"" << get_minutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\","; - out << "\"SHORTEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].shortest_time.seconds) << "\","; - out << "\"LONGEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].longest_time.seconds) << "\","; + out << "\"AVERAGE_TIME\":\"" << formatMinutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\","; + out << "\"SHORTEST_TIME\":\"" << formatMinutes(stats.stats_yearly[i].shortest_time.seconds) << "\","; + out << "\"LONGEST_TIME\":\"" << formatMinutes(stats.stats_yearly[i].longest_time.seconds) << "\","; out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\","; out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\","; out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\","; diff --git a/core/statistics.c b/core/statistics.c index 78e65a3eb..5707e6c5e 100644 --- a/core/statistics.c +++ b/core/statistics.c @@ -2,7 +2,6 @@ /* statistics.c * * core logic for the Info & Stats page - - * char *get_minutes(int seconds); * void calculate_stats_summary(struct stats_summary *out, bool selected_only); * void calculate_stats_selected(stats_t *stats_selection); */ @@ -84,13 +83,6 @@ static void process_dive(struct dive *dive, stats_t *stats) } } -char *get_minutes(int seconds) -{ - static char buf[80]; - snprintf(buf, sizeof(buf), "%d:%.2d", FRACTION(seconds, 60)); - return buf; -} - /* * Calculate a summary of the statistics and put in the stats_summary * structure provided in the first parameter. diff --git a/core/statistics.h b/core/statistics.h index ef702ea15..4b2b0b1bb 100644 --- a/core/statistics.h +++ b/core/statistics.h @@ -58,7 +58,6 @@ struct stats_summary { extern "C" { #endif -extern char *get_minutes(int seconds); extern void init_stats_summary(struct stats_summary *stats); extern void free_stats_summary(struct stats_summary *stats); extern void calculate_stats_summary(struct stats_summary *stats, bool selected_only); diff --git a/core/string-format.cpp b/core/string-format.cpp index 0526d3653..8c8264cc5 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -277,6 +277,11 @@ QString formatDayOfWeek(int day) } } +QString formatMinutes(int seconds) +{ + return QString::asprintf("%d:%.2d", FRACTION(seconds, 60)); +} + QString formatTripTitle(const dive_trip *trip) { if (!trip) diff --git a/core/string-format.h b/core/string-format.h index 67221b540..51ae70df0 100644 --- a/core/string-format.h +++ b/core/string-format.h @@ -27,6 +27,7 @@ QString formatDiveDate(const dive *d); QString formatDiveTime(const dive *d); QString formatDiveDateTime(const dive *d); QString formatDayOfWeek(int day); +QString formatMinutes(int seconds); QString formatTripTitle(const dive_trip *trip); QString formatTripTitleWithDives(const dive_trip *trip); diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index 46e7db912..c79a4c205 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -464,11 +464,11 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s return get_dive_duration_string(object->total_time.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " "); } else if (property == "avg_time") { - return get_minutes(object->total_time.seconds / object->selection_size); + return formatMinutes(object->total_time.seconds / object->selection_size); } else if (property == "shortest_time") { - return get_minutes(object->shortest_time.seconds); + return formatMinutes(object->shortest_time.seconds); } else if (property == "longest_time") { - return get_minutes(object->longest_time.seconds); + return formatMinutes(object->longest_time.seconds); } else if (property == "avg_depth") { return get_depth_string(object->avg_depth); } else if (property == "min_depth") { diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp index d280808e9..dd570e361 100644 --- a/qt-models/yearlystatisticsmodel.cpp +++ b/qt-models/yearlystatisticsmodel.cpp @@ -3,6 +3,7 @@ #include "core/qthelper.h" #include "core/metrics.h" #include "core/statistics.h" +#include "core/string-format.h" #include "core/dive.h" // For NUM_DIVEMODE class YearStatisticsItem : public TreeItem { @@ -65,13 +66,13 @@ QVariant YearStatisticsItem::data(int column, int role) const ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " "); break; case AVERAGE_TIME: - ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); + ret = formatMinutes(stats_interval.total_time.seconds / stats_interval.selection_size); break; case SHORTEST_TIME: - ret = get_minutes(stats_interval.shortest_time.seconds); + ret = formatMinutes(stats_interval.shortest_time.seconds); break; case LONGEST_TIME: - ret = get_minutes(stats_interval.longest_time.seconds); + ret = formatMinutes(stats_interval.longest_time.seconds); break; case AVG_DEPTH: ret = get_depth_string(stats_interval.avg_depth);