summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divelist-gtk.c20
-rw-r--r--divelist.c30
-rw-r--r--divelist.h2
3 files changed, 36 insertions, 16 deletions
diff --git a/divelist-gtk.c b/divelist-gtk.c
index acb908a18..2f6e12de7 100644
--- a/divelist-gtk.c
+++ b/divelist-gtk.c
@@ -261,31 +261,19 @@ static void date_data_func(GtkTreeViewColumn *col,
struct tm tm;
timestamp_t when;
/* this should be enought for most languages. if not increase the value. */
- char buffer[256];
+ char *buffer;
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
nr = gtk_tree_model_iter_n_children(model, iter);
utc_mkdate(when, &tm);
if (idx < 0) {
- snprintf(buffer, sizeof(buffer),
- /*++GETTEXT 60 char buffer weekday, monthname, day of month, year, nr dives */
- ngettext("Trip %1$s, %2$s %3$d, %4$d (%5$d dive)",
- "Trip %1$s, %2$s %3$d, %4$d (%5$d dives)", nr),
- weekday(tm.tm_wday),
- monthname(tm.tm_mon),
- tm.tm_mday, tm.tm_year + 1900,
- nr);
+ buffer = get_trip_date_string(&tm, nr);
} else {
- snprintf(buffer, sizeof(buffer),
- /*++GETTEXT 60 char buffer weekday, monthname, day of month, year, hour:min */
- _("%1$s, %2$s %3$d, %4$d %5$02d:%6$02d"),
- weekday(tm.tm_wday),
- monthname(tm.tm_mon),
- tm.tm_mday, tm.tm_year + 1900,
- tm.tm_hour, tm.tm_min);
+ buffer = get_dive_date_string(&tm);
}
g_object_set(renderer, "text", buffer, NULL);
+ free(buffer);
}
static void depth_data_func(GtkTreeViewColumn *col,
diff --git a/divelist.c b/divelist.c
index d105da52e..3be95e3e9 100644
--- a/divelist.c
+++ b/divelist.c
@@ -559,6 +559,36 @@ void get_suit(struct dive *dive, char **str)
get_string(str, dive->suit);
}
+#define MAX_DATE_STRING 256
+/* caller needs to free the string */
+char *get_dive_date_string(struct tm *tm) {
+ char *buffer = malloc(MAX_DATE_STRING);
+ if (buffer)
+ snprintf(buffer, MAX_DATE_STRING,
+ /*++GETTEXT 60 char buffer weekday, monthname, day of month, year, hour:min */
+ _("%1$s, %2$s %3$d, %4$d %5$02d:%6$02d"),
+ weekday(tm->tm_wday),
+ monthname(tm->tm_mon),
+ tm->tm_mday, tm->tm_year + 1900,
+ tm->tm_hour, tm->tm_min);
+ return buffer;
+}
+
+/* caller needs to free the string */
+char *get_trip_date_string(struct tm *tm, int nr) {
+ char *buffer = malloc(MAX_DATE_STRING);
+ if (buffer)
+ snprintf(buffer, MAX_DATE_STRING,
+ /*++GETTEXT 60 char buffer weekday, monthname, day of month, year, nr dives */
+ ngettext("Trip %1$s, %2$s %3$d, %4$d (%5$d dive)",
+ "Trip %1$s, %2$s %3$d, %4$d (%5$d dives)", nr),
+ weekday(tm->tm_wday),
+ monthname(tm->tm_mon),
+ tm->tm_mday, tm->tm_year + 1900,
+ nr);
+ return buffer;
+}
+
/*
* helper functions for dive_trip handling
*/
diff --git a/divelist.h b/divelist.h
index ac7953287..5d30e9b1d 100644
--- a/divelist.h
+++ b/divelist.h
@@ -22,6 +22,8 @@ extern void upload_all_dives_divelogs_cb();
#endif
/* divelist core logic functions */
+extern char *get_dive_date_string(struct tm *tm);
+extern char *get_trip_date_string(struct tm *tm, int nr);
extern void clear_trip_indexes(void);
extern dive_trip_t *find_trip_by_idx(int idx);
extern int dive_nr_sort(int idx_a, int idx_b, timestamp_t when_a, timestamp_t when_b);