]> granicus.if.org Git - cgit/commitdiff
ui-shared: extract date formatting to a function
authorJohn Keeping <john@keeping.me.uk>
Thu, 13 Aug 2015 11:24:32 +0000 (12:24 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 13 Aug 2015 13:39:59 +0000 (15:39 +0200)
This will allow this code to be common with print_rel_date.

Signed-off-by: John Keeping <john@keeping.me.uk>
ui-shared.c

index 1292ac99d0cf43ce4c5fcf85614aa9db689c7195..19cd52178cc22320ecb92ac6ffab8e90fb493ed3 100644 (file)
@@ -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,