summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-06-22 14:15:25 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-22 14:15:25 -0700
commit9eafe86d58a2d2b30e8b33f6697519fc7f104443 (patch)
tree511646eac969baa9feef1b949696a5b6a66e94d8 /date.c
parent1565b18791b4b27ab464764d37b86a673165ab07 (diff)
parent6eced3ec5e5d7fbe61de2791e2627b1acf1246b3 (diff)
downloadgit-9eafe86d58a2d2b30e8b33f6697519fc7f104443.tar.gz
Merge branch 'rs/strbuf-addftime-zZ'
As there is no portable way to pass timezone information to strftime, some output format from "git log" and friends are impossible to produce. Teach our own strbuf_addftime to replace %z and %Z with caller-supplied values to help working around this. * rs/strbuf-addftime-zZ: date: use localtime() for "-local" time formats t0006: check --date=format zone offsets strbuf: let strbuf_addftime handle %z and %Z itself
Diffstat (limited to 'date.c')
-rw-r--r--date.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/date.c b/date.c
index 63fa99685e..1fd6d66375 100644
--- a/date.c
+++ b/date.c
@@ -70,6 +70,12 @@ static struct tm *time_to_tm(timestamp_t time, int tz)
return gmtime(&t);
}
+static struct tm *time_to_tm_local(timestamp_t time)
+{
+ time_t t = time;
+ return localtime(&t);
+}
+
/*
* What value of "tz" was in effect back then at "time" in the
* local timezone?
@@ -214,7 +220,10 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
return timebuf.buf;
}
- tm = time_to_tm(time, tz);
+ if (mode->local)
+ tm = time_to_tm_local(time);
+ else
+ tm = time_to_tm(time, tz);
if (!tm) {
tm = time_to_tm(0, 0);
tz = 0;
@@ -246,7 +255,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
month_names[tm->tm_mon], tm->tm_year + 1900,
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
else if (mode->type == DATE_STRFTIME)
- strbuf_addftime(&timebuf, mode->strftime_fmt, tm);
+ strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
+ mode->local ? NULL : "");
else
strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
weekday_names[tm->tm_wday],