git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [RFC PATCH] Add 'human' date format
Date: Sat, 7 Jul 2018 13:12:33 -0700	[thread overview]
Message-ID: <CA+55aFy=rUvt8kV==Zxvc02zaTQpd=Zc0p6dMN=vHvvoYE4bYw@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFyh4=Udhfn+L__9MiCbjqSLTWBGaAvDOPg5EJWs-DjjPQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

On Sat, Jul 7, 2018 at 12:58 PM Linus Torvalds
<torvalds@linux-foundation.org> 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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1743 bytes --]

 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;
 }
 

  reply	other threads:[~2018-07-07 20:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-07 19:38 [RFC PATCH] Add 'human' date format Linus Torvalds
2018-07-07 19:58 ` Linus Torvalds
2018-07-07 20:12   ` Linus Torvalds [this message]
2018-07-07 22:02 ` [RFC PATCH v2] " Linus Torvalds
2018-07-11 20:34   ` Andrei Rybak
2018-07-11 20:38     ` Andrei Rybak
2018-07-11 20:54       ` Junio C Hamano
2018-07-11 20:49     ` Linus Torvalds
2018-07-11 21:23       ` Linus Torvalds
2018-07-11 21:24   ` Ævar Arnfjörð Bjarmason
2018-07-11 21:49     ` Linus Torvalds
2018-07-24 21:49   ` Junio C Hamano
2018-07-24 22:58     ` Linus Torvalds
2018-11-27  4:10   ` Stephen P. Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+55aFy=rUvt8kV==Zxvc02zaTQpd=Zc0p6dMN=vHvvoYE4bYw@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).