summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-06-25 16:55:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-29 18:39:10 (GMT)
commitaa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d (patch)
tree59ef52faaddb398ce95f3564ea5bd895c69e047f /date.c
parenta5481a6c9438cbd9c246cfa59ff49c31a0926fb6 (diff)
downloadgit-aa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d.zip
git-aa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d.tar.gz
git-aa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d.tar.bz2
introduce "format" date-mode
This feeds the format directly to strftime. Besides being a little more flexible, the main advantage is that your system strftime may know more about your locale's preferred format (e.g., how to spell the days of the week). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-rw-r--r--date.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/date.c b/date.c
index cdad4db..8f91569 100644
--- a/date.c
+++ b/date.c
@@ -163,6 +163,8 @@ void show_date_relative(unsigned long time, int tz,
struct date_mode *date_mode_from_type(enum date_mode_type type)
{
static struct date_mode mode;
+ if (type == DATE_STRFTIME)
+ die("BUG: cannot create anonymous strftime date_mode struct");
mode.type = type;
return &mode;
}
@@ -221,6 +223,8 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
weekday_names[tm->tm_wday], tm->tm_mday,
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);
else
strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
weekday_names[tm->tm_wday],
@@ -787,7 +791,10 @@ void parse_date_format(const char *format, struct date_mode *mode)
mode->type = DATE_NORMAL;
else if (!strcmp(format, "raw"))
mode->type = DATE_RAW;
- else
+ else if (skip_prefix(format, "format:", &format)) {
+ mode->type = DATE_STRFTIME;
+ mode->strftime_fmt = xstrdup(format);
+ } else
die("unknown date format %s", format);
}