]> git.armaanb.net Git - stagit.git/commitdiff
simplify time format
authorHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 7 Dec 2015 22:22:18 +0000 (23:22 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 7 Dec 2015 22:22:18 +0000 (23:22 +0100)
urmoms.c

index 7d41fbbba2da8756283dc1e15b12b03051bd32fa..76e168adad4e5156e6fab052e15313d89af4f679 100644 (file)
--- a/urmoms.c
+++ b/urmoms.c
@@ -48,7 +48,6 @@ commitinfo_free(struct commitinfo *ci)
        if (!ci)
                return;
 
-       /* TODO: print error ? */
        git_diff_stats_free(ci->stats);
        git_diff_free(ci->diff);
        git_commit_free(ci->commit);
@@ -188,56 +187,34 @@ xbasename(const char *path)
 }
 
 void
-printtimez(FILE *fp, const git_time *intime)
+printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
 {
        struct tm *intm;
        time_t t;
-       int offset, hours, minutes;
-       char sign, out[32];
-
-       offset = intime->offset;
-       if (offset < 0) {
-               sign = '-';
-               offset = -offset;
-       } else {
-               sign = '+';
-       }
-
-       hours = offset / 60;
-       minutes = offset % 60;
+       char out[32];
 
        t = (time_t) intime->time + (intime->offset * 60);
-
        intm = gmtime(&t);
-       strftime(out, sizeof(out), "%Y-%m-%dT%H:%M:%SZ", intm);
+       strftime(out, sizeof(out), fmt, intm);
        fputs(out, fp);
 }
 
 void
-printtime(FILE *fp, const git_time *intime)
+printtimez(FILE *fp, const git_time *intime)
 {
-       struct tm *intm;
-       time_t t;
-       int offset, hours, minutes;
-       char sign, out[32];
-
-       offset = intime->offset;
-       if (offset < 0) {
-               sign = '-';
-               offset = -offset;
-       } else {
-               sign = '+';
-       }
-
-       hours = offset / 60;
-       minutes = offset % 60;
-
-       t = (time_t) intime->time + (intime->offset * 60);
+       printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
+}
 
-       intm = gmtime(&t);
-       strftime(out, sizeof(out), "%a %b %e %T %Y", intm);
+void
+printtime(FILE *fp, const git_time *intime)
+{
+       printtimeformat(fp, intime, "%a %b %e %T %Y");
+}
 
-       fprintf(fp, "%s %c%02d%02d", out, sign, hours, minutes);
+void
+printtimeshort(FILE *fp, const git_time *intime)
+{
+       printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
 }
 
 void