Creation of dive duration string and surface interval string

Update the function to create the dive duration string in a way that
it can be used also in info and stats tab and added some more flexibility.

Changed layout for <1h freedives to "0:05:35" (w/o units) or "5:35min"
(with units and :) or "5min 35sec" (with units with space).

Add a new function to create the surface interval string.

Completely remove old function get_time_string() and get_time_string_s().

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
Stefan Fuchs 2017-05-11 22:43:36 +02:00 committed by Dirk Hohndel
parent 53a8075bd8
commit e6d884cf26
13 changed files with 68 additions and 48 deletions

View file

@ -2,7 +2,6 @@
/* statistics.c
*
* core logic for the Info & Stats page -
* char *get_time_string(int seconds, int maxdays);
* char *get_minutes(int seconds);
* void process_all_dives(struct dive *dive, struct dive **prev_dive);
* void get_selected_dives_text(char *buffer, int size);
@ -236,27 +235,6 @@ void process_selected_dives(void)
stats_selection.selection_size = nr;
}
char *get_time_string_s(int seconds, int maxdays, bool freediving)
{
static char buf[80];
if (maxdays && seconds > 3600 * 24 * maxdays) {
snprintf(buf, sizeof(buf), translate("gettextFromC", "more than %d days"), maxdays);
} else {
int days = seconds / 3600 / 24;
int hours = (seconds - days * 3600 * 24) / 3600;
int minutes = (seconds - days * 3600 * 24 - hours * 3600) / 60;
int secs = (seconds - days * 3600 * 24 - hours * 3600 - minutes*60);
if (days > 0)
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dd %dh %dmin"), days, hours, minutes);
else
if (freediving && seconds < 3600)
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dmin %dsecs"), minutes, secs);
else
snprintf(buf, sizeof(buf), translate("gettextFromC", "%dh %dmin"), hours, minutes);
}
return buf;
}
/* this gets called when at least two but not all dives are selected */
static void get_ranges(char *buffer, int size)
{