date: add "unix" format
We already have "--date=raw", which is a Unix epoch timestamp plus a contextual timezone (either the author's or the local). But one may not care about the timezone and just want the epoch timestamp by itself. It's not hard to parse the two apart, but if you are using a pretty-print format, you may want git to show the "finished" form that the user will see. We can accomodate this by adding a new date format, "unix", which is basically "raw" without the timezone. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1a2a1e8eb9
commit
642833db78
8
date.c
8
date.c
@ -177,6 +177,12 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
|
||||
struct tm *tm;
|
||||
static struct strbuf timebuf = STRBUF_INIT;
|
||||
|
||||
if (mode->type == DATE_UNIX) {
|
||||
strbuf_reset(&timebuf);
|
||||
strbuf_addf(&timebuf, "%lu", time);
|
||||
return timebuf.buf;
|
||||
}
|
||||
|
||||
if (mode->local)
|
||||
tz = local_tzoffset(time);
|
||||
|
||||
@ -792,6 +798,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
|
||||
return DATE_NORMAL;
|
||||
if (skip_prefix(format, "raw", end))
|
||||
return DATE_RAW;
|
||||
if (skip_prefix(format, "unix", end))
|
||||
return DATE_UNIX;
|
||||
if (skip_prefix(format, "format", end))
|
||||
return DATE_STRFTIME;
|
||||
|
||||
|
Reference in New Issue
Block a user