From c5c6741b0a7cc41f1f7976c47d7f41320d57508c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 7 Dec 2015 23:22:18 +0100 Subject: [PATCH] simplify time format --- urmoms.c | 53 +++++++++++++++-------------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/urmoms.c b/urmoms.c index 7d41fbb..76e168a 100644 --- 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 -- libgit2 1.1.1