summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-18 13:18:09 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-18 13:18:09 -0700
commit75765be14cc90886d7f46ec02097b7efeb3d8234 (patch)
tree8029786e6399bc0a1298005263afc74c37452add /divelist.c
parent1a15462073d854674e4d745c6af0249a1d48452e (diff)
downloadsubsurface-75765be14cc90886d7f46ec02097b7efeb3d8234.tar.gz
Move creation of dive and dive trip date string into helper functions
This allows this code to easily be shared by Gtk and Qt UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c
index 088b0e626..42fb272b0 100644
--- a/divelist.c
+++ b/divelist.c
@@ -489,6 +489,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
*/