[PATCH 1/3] ui-shared: extract date formatting to a function

John Keeping john at keeping.me.uk
Thu Aug 13 13:24:32 CEST 2015


This will allow this code to be common with print_rel_date.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 6be0c2e..a6d4b65 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -604,19 +604,24 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
 		path[len - 1] = tail;
 }
 
-void cgit_print_date(time_t secs, const char *format, int local_time)
+static const char *fmt_date(time_t secs, const char *format, int local_time)
 {
-	char buf[64];
+	static char buf[64];
 	struct tm *time;
 
 	if (!secs)
-		return;
+		return "";
 	if (local_time)
 		time = localtime(&secs);
 	else
 		time = gmtime(&secs);
 	strftime(buf, sizeof(buf)-1, format, time);
-	html_txt(buf);
+	return buf;
+}
+
+void cgit_print_date(time_t secs, const char *format, int local_time)
+{
+	html_txt(fmt_date(secs, format, local_time));
 }
 
 static void print_rel_date(time_t t, double value,
-- 
2.5.0.466.g9af26fa



More information about the CGit mailing list