stagit

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.

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 382337d parent: d376719
2 files changed, 30 insertions(+), 20 deletions(-)
Mstagit-index.c+3-9
Mstagit.c+27-11
M · stagit-index.c +3, -9
 1@@ -42,25 +42,19 @@ xmlencode(FILE *fp, const char *s, size_t len)
 2 }
 3 
 4 void
 5-printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
 6+printtimeshort(FILE *fp, const git_time *intime)
 7 {
 8 	struct tm *intm;
 9 	time_t t;
10 	char out[32];
11 
12-	t = (time_t) intime->time + (intime->offset * 60);
13+	t = (time_t)intime->time;
14 	if (!(intm = gmtime(&t)))
15 		return;
16-	strftime(out, sizeof(out), fmt, intm);
17+	strftime(out, sizeof(out), "%Y-%m-%d %H:%M", intm);
18 	fputs(out, fp);
19 }
20 
21-void
22-printtimeshort(FILE *fp, const git_time *intime)
23-{
24-	printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
25-}
26-
27 int
28 writeheader(FILE *fp)
29 {
M · stagit.c +27, -11
 1@@ -268,35 +268,51 @@ mkdirp(const char *path)
 2 }
 3 
 4 void
 5-printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
 6+printtimez(FILE *fp, const git_time *intime)
 7 {
 8 	struct tm *intm;
 9 	time_t t;
10 	char out[32];
11 
12-	t = (time_t) intime->time + (intime->offset * 60);
13+	t = (time_t)intime->time;
14 	if (!(intm = gmtime(&t)))
15 		return;
16-	strftime(out, sizeof(out), fmt, intm);
17+	strftime(out, sizeof(out), "%Y-%m-%dT%H:%M:%SZ", intm);
18 	fputs(out, fp);
19 }
20 
21-void
22-printtimez(FILE *fp, const git_time *intime)
23-{
24-	printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
25-}
26-
27 void
28 printtime(FILE *fp, const git_time *intime)
29 {
30-	printtimeformat(fp, intime, "%a %b %e %T %Y");
31+	struct tm *intm;
32+	time_t t;
33+	int offset, sign = '+';
34+	char out[32];
35+
36+	offset = intime->offset * 60;
37+	t = (time_t)intime->time + offset;
38+	if (!(intm = gmtime(&t)))
39+		return;
40+	strftime(out, sizeof(out), "%a %b %e %H:%M:%S", intm);
41+	if (offset < 0) {
42+		offset = -offset;
43+		sign = '-';
44+	}
45+	fprintf(fp, "%s %c%02d%02d", out, sign, offset / 60, offset % 60);
46 }
47 
48 void
49 printtimeshort(FILE *fp, const git_time *intime)
50 {
51-	printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
52+	struct tm *intm;
53+	time_t t;
54+	char out[32];
55+
56+	t = (time_t)intime->time;
57+	if (!(intm = gmtime(&t)))
58+		return;
59+	strftime(out, sizeof(out), "%Y-%m-%d %H:%M", intm);
60+	fputs(out, fp);
61 }
62 
63 int