summaryrefslogtreecommitdiff
path: root/stagit.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-05-01 16:10:17 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-05-01 16:56:58 +0200
commit462ba66ee7e0ae16f41d4fff9c8540913c3941a9 (patch)
tree52e9a091d70fa7e885a69b365f803cbd3bf61597 /stagit.c
parent7a1da0b9853093781dd1b130d63619b17ecc8c01 (diff)
fix times (and timezone)
- in the index and log show the short time (GMT). - in the Atom feed use GMT time. - for commits show the time + offset.
Diffstat (limited to 'stagit.c')
-rw-r--r--stagit.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/stagit.c b/stagit.c
index 24a630d..cb2c1c9 100644
--- a/stagit.c
+++ b/stagit.c
@@ -268,35 +268,51 @@ mkdirp(const char *path)
}
void
-printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
+printtimez(FILE *fp, const git_time *intime)
{
struct tm *intm;
time_t t;
char out[32];
- t = (time_t) intime->time + (intime->offset * 60);
+ t = (time_t)intime->time;
if (!(intm = gmtime(&t)))
return;
- strftime(out, sizeof(out), fmt, intm);
+ strftime(out, sizeof(out), "%Y-%m-%dT%H:%M:%SZ", intm);
fputs(out, fp);
}
void
-printtimez(FILE *fp, const git_time *intime)
-{
- printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
-}
-
-void
printtime(FILE *fp, const git_time *intime)
{
- printtimeformat(fp, intime, "%a %b %e %T %Y");
+ struct tm *intm;
+ time_t t;
+ int offset, sign = '+';
+ char out[32];
+
+ offset = intime->offset * 60;
+ t = (time_t)intime->time + offset;
+ if (!(intm = gmtime(&t)))
+ return;
+ strftime(out, sizeof(out), "%a %b %e %H:%M:%S", intm);
+ if (offset < 0) {
+ offset = -offset;
+ sign = '-';
+ }
+ fprintf(fp, "%s %c%02d%02d", out, sign, offset / 60, offset % 60);
}
void
printtimeshort(FILE *fp, const git_time *intime)
{
- printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
+ struct tm *intm;
+ time_t t;
+ char out[32];
+
+ t = (time_t)intime->time;
+ if (!(intm = gmtime(&t)))
+ return;
+ strftime(out, sizeof(out), "%Y-%m-%d %H:%M", intm);
+ fputs(out, fp);
}
int