On Sat, Jul 7, 2018 at 12:58 PM Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote: > > I'm playing with making all "today" dates just use the relative > format. Here's the incremental patch for that if people want to compare the output. With this, you never get the "just time" case, because that will turn into "2 hours ago" or similar. But you will get "Fri 19:45" for something that happened yesterday. So examples from my kernel logs look something like this: 2 hours ago Fri 19:45 Fri 10:44 +1000 Fri Jun 22 15:46 Tue Jun 19 15:41 -0600 Thu Jun 15 12:57 2017 +0300 depending on how long ago they were and whether they were in the same timezone etc. Linus
date.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/date.c b/date.c index 9809ac334..de0b03cf4 100644 --- a/date.c +++ b/date.c @@ -199,7 +199,7 @@ struct date_mode *date_mode_from_type(enum date_mode_type type) return &mode; } -static void show_date_normal(struct strbuf *buf, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local) +static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local) { struct { unsigned int year:1, @@ -225,6 +225,14 @@ static void show_date_normal(struct strbuf *buf, struct tm *tm, int tz, struct t } } + /* Show "today" times as just relative times */ + if (hide.wday) { + struct timeval now; + gettimeofday(&now, NULL); + show_date_relative(time, tz, &now, buf); + return; + } + /* Always hide seconds for human-readable */ hide.seconds = human_tm->tm_year > 0; @@ -268,10 +276,6 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) /* Fill in the data for "current time" in human_tz and human_tm */ human_tz = local_time_tzoffset(now.tv_sec, &human_tm); - /* Special case: if it's less than an hour ago, use relative time */ - if (time - now.tv_sec < 60 * 60) - type = DATE_RELATIVE; - /* Don't print timezone if it matches */ if (tz == human_tz) local = 1; @@ -333,7 +337,7 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz, !local); else - show_date_normal(&timebuf, tm, tz, &human_tm, human_tz, local); + show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, local); return timebuf.buf; }