Skip to contentSkip to conversation

--date=relative falls back to "short" format for commits older than a year

PATCH In review [email protected] 5 participants 15 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 --date=relative falls back to "short" format for commits older than a year

From: Eugene Letuchy <[email protected]>

In the context of sizing the git blame time column, it doesn't make a lot of sense to see "12 months ago" next to an exact timestamp + timezone for something 13 months ago. This commit makes commits older than 12 months display the date only, not the time.

---
 builtin-blame.c |    5 ++---
 date.c          |    4 +++-
 2 files changed, 5 insertions(+), 4 deletions(-)
builtin-blame.c +2 -3
index aa5c66c..48cedfd 100644
@@ -2286,9 +2286,8 @@ parse_done:
 		blame_date_width = sizeof("2006-10-19");
 		break;
 	case DATE_RELATIVE:
-		/* unfortunately "normal" is the fallback for "relative" */
-		/* blame_date_width = sizeof("14 minutes ago"); */
-		/* break; */
+		blame_date_width = sizeof("14 minutes ago");
+		break;
 	case DATE_LOCAL:
 	case DATE_NORMAL:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
date.c +3 -1
index 950b88f..edb2078 100644
@@ -128,7 +128,9 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 			snprintf(timebuf, sizeof(timebuf), "%lu months ago", (diff + 15) / 30);
 			return timebuf;
 		}
-		/* Else fall back on absolute format.. */
+
+		/* Else fall back to the short format */
+		mode = DATE_SHORT;
 	}
 
 	if (mode == DATE_LOCAL)
Signature · 1 line
1.6.2.rc1.14.g07c3.dirty
#1 lore raw

Subject: Support 'raw' date format

Talking about --date, one thing I wanted for the 1234567890 date was to get things in the raw format. Sure, you get them with --pretty=raw, but it felt a bit sad that you couldn't just ask for the date in raw format.

So here's a throw-away patch (meaning: I won't be re-sending it, because I really don't think it's a big deal) to add "--date=raw". It just prints out the internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format)

---

Not a whole lot of testing. But

	git show --date=raw v2.6.29-rc5

works correctly.

 Documentation/rev-list-options.txt |    4 +++-
 cache.h                            |    3 ++-
 date.c                             |    7 +++++++
 3 files changed, 12 insertions(+), 2 deletions(-)
Documentation/rev-list-options.txt +3 -1
index b9f6e4d..5076322 100644
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
 
 	Synonym for `--date=relative`.
 
---date={relative,local,default,iso,rfc,short}::
+--date={relative,local,default,iso,rfc,short,raw}::
 
 	Only takes effect for dates shown in human-readable format, such
 	as when using "--pretty". `log.date` config variable sets a default
@@ -31,6 +31,8 @@ format, often found in E-mail messages.
 +
 `--date=short` shows only date but not time, in `YYYY-MM-DD` format.
 +
+`--date=raw` shows the date in the internal raw git format `%s %z` format.
++
 `--date=default` shows timestamps in the original timezone
 (either committer's or author's).
 
cache.h +2 -1
index 21a6310..189151d 100644
@@ -696,7 +696,8 @@ enum date_mode {
 	DATE_SHORT,
 	DATE_LOCAL,
 	DATE_ISO8601,
-	DATE_RFC2822
+	DATE_RFC2822,
+	DATE_RAW
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
date.c +7 -0
index 950b88f..d75dff4 100644
@@ -89,6 +89,11 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 	struct tm *tm;
 	static char timebuf[200];
 
+	if (mode == DATE_RAW) {
+		snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
+		return timebuf;
+	}
+
 	if (mode == DATE_RELATIVE) {
 		unsigned long diff;
 		struct timeval now;
@@ -615,6 +620,8 @@ enum date_mode parse_date_format(const char *format)
 		return DATE_LOCAL;
 	else if (!strcmp(format, "default"))
 		return DATE_NORMAL;
+	else if (!strcmp(format, "raw"))
+		return DATE_RAW;
 	else
 		die("unknown date format %s", format);
 }
#2 lore raw
Quoted 4 lines · Linus Torvalds

So here's a throw-away patch (meaning: I won't be re-sending it, because I really don't think it's a big deal) to add "--date=raw". It just prints out the internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format)

Heh, who can discard a patch *WITH DOCUMENTATION* from you ;-)

Thanks.

#3 lore raw
In reply to Linus Torvalds

Cool. I think git blame would need to be tweaked a bit after my patch (at least documentation wise), since it already has a "raw timestamp" option (-t).

Quoted 88 lines · Linus Torvalds

Subject: Support 'raw' date format

Talking about --date, one thing I wanted for the 1234567890 date was to get things in the raw format. Sure, you get them with --pretty=raw, but it felt a bit sad that you couldn't just ask for the date in raw format.

So here's a throw-away patch (meaning: I won't be re-sending it, because I really don't think it's a big deal) to add "--date=raw". It just prints out the internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format)

---

Not a whole lot of testing. But

       git show --date=raw v2.6.29-rc5

works correctly.

 Documentation/rev-list-options.txt |    4 +++-
 cache.h                            |    3 ++-
 date.c                             |    7 +++++++
 3 files changed, 12 insertions(+), 2 deletions(-)
Documentation/rev-list-options.txt +3 -1
index b9f6e4d..5076322 100644
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
 
       Synonym for `--date=relative`.
 
---date={relative,local,default,iso,rfc,short}::
+--date={relative,local,default,iso,rfc,short,raw}::
 
       Only takes effect for dates shown in human-readable format, such
       as when using "--pretty". `log.date` config variable sets a default
@@ -31,6 +31,8 @@ format, often found in E-mail messages.
 +
 `--date=short` shows only date but not time, in `YYYY-MM-DD` format.
 +
+`--date=raw` shows the date in the internal raw git format `%s %z` format.
++
 `--date=default` shows timestamps in the original timezone
 (either committer's or author's).
 
cache.h +2 -1
index 21a6310..189151d 100644
@@ -696,7 +696,8 @@ enum date_mode {
       DATE_SHORT,
       DATE_LOCAL,
       DATE_ISO8601,
-       DATE_RFC2822
+       DATE_RFC2822,
+       DATE_RAW
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
date.c +7 -0
index 950b88f..d75dff4 100644
@@ -89,6 +89,11 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
       struct tm *tm;
       static char timebuf[200];
 
+       if (mode == DATE_RAW) {
+               snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
+               return timebuf;
+       }
+
       if (mode == DATE_RELATIVE) {
               unsigned long diff;
               struct timeval now;
@@ -615,6 +620,8 @@ enum date_mode parse_date_format(const char *format)
               return DATE_LOCAL;
       else if (!strcmp(format, "default"))
               return DATE_NORMAL;
+       else if (!strcmp(format, "raw"))
+               return DATE_RAW;
       else
               die("unknown date format %s", format);
 }
Signature · 1 line
Eugene
#4 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, Feb 20, 2009 at 01:23:54PM -0800, [email protected] wrote:

From: Eugene Letuchy <[email protected]>

In the context of sizing the git blame time column, it doesn't make a lot of sense to see "12 months ago" next to an exact timestamp + timezone for something 13 months ago. This commit makes commits older than 12 months display the date only, not the time.

I think this is an improvement, though I was thinking of taking it a step further:

date.c +5 -3
index d75dff4..6dbb8e8 100644
@@ -128,12 +128,14 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 			snprintf(timebuf, sizeof(timebuf), "%lu weeks ago", (diff + 3) / 7);
 			return timebuf;
 		}
-		/* Say months for the past 12 months or so */
-		if (diff < 360) {
+		/* Say months for the past 24 months or so */
+		if (diff < 720) {
 			snprintf(timebuf, sizeof(timebuf), "%lu months ago", (diff + 15) / 30);
 			return timebuf;
 		}
-		/* Else fall back on absolute format.. */
+		/* Otherwise, years. Centuries is probably overkill. */
+		snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365);
+		return timebuf;
 	}
 
 	if (mode == DATE_LOCAL)

but maybe other people actually like seeing the absolute time. I've always found it jarring when reading relative times (but part of that _was_ because it was so long and exact).

-Peff

#5 lore raw
Quoted 20 lines · Jeff King
Quoted 6 lines · On Fri, Feb 20, 2009 at 01:23:54PM -0800, [email protected] wrote:

From: Eugene Letuchy <[email protected]>

In the context of sizing the git blame time column, it doesn't make a lot of sense to see "12 months ago" next to an exact timestamp + timezone for something 13 months ago. This commit makes commits older than 12 months display the date only, not the time.

I think this is an improvement, though I was thinking of taking it a step further:
...

date.c +3 -0
+		/* Otherwise, years. Centuries is probably overkill. */
+		snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365);
+		return timebuf;
 	}
 
 	if (mode == DATE_LOCAL)
Quoted 3 lines

but maybe other people actually like seeing the absolute time. I've always found it jarring when reading relative times (but part of that _was_ because it was so long and exact).

I agree this is an improvement. It irritated me, too. And I do not think this change falls into the category of bad backward incompatibility.

I was hoping somebody would do a "N years M months", though.

#6 lore raw
Quoted 8 lines · Junio C Hamano

date.c const char *show_date(unsigned long time, int tz, enum date_mode mode) · line 138

Quoted 3 lines
date.c +3 -0
+		/* Otherwise, years. Centuries is probably overkill. */
+		snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365);
+		return timebuf;

I agree this is an improvement. It irritated me, too. And I do not think this change falls into the category of bad backward incompatibility.

I was hoping somebody would do a "N years M months", though.

I thought about that, but I wanted to keep the maximum size down for column output (like in git-blame). Which is why I bumped the "use months" limit to 24 months instead of 12.

And that limit can also be tweaked. Surely at some point there is a range where you no longer care about the months and "N years" has high enough resolution. But there is also a point where "N months" gets cumbersome (75 months is a more annoying than "around 6 years"). The question is whether we reach the "cumbersome" point before we reach the "don't care about months" point.

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

-Peff

#7 lore raw

Jeff King said the following on 23.02.2009 04:16:

Quoted 21 lines · Junio C Hamano
Quoted 8 lines

date.c const char *show_date(unsigned long time, int tz, enum date_mode mode) · line 138

Quoted 3 lines
date.c +3 -0
+		/* Otherwise, years. Centuries is probably overkill. */
+		snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365);
+		return timebuf;

I agree this is an improvement. It irritated me, too. And I do not think this change falls into the category of bad backward incompatibility.

I was hoping somebody would do a "N years M months", though.

I thought about that, but I wanted to keep the maximum size down for column output (like in git-blame). Which is why I bumped the "use months" limit to 24 months instead of 12.

And that limit can also be tweaked. Surely at some point there is a range where you no longer care about the months and "N years" has high enough resolution. But there is also a point where "N months" gets cumbersome (75 months is a more annoying than "around 6 years"). The question is whether we reach the "cumbersome" point before we reach the "don't care about months" point.

Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

And using shorter names for the units would be a no-go?

"3y 2m ago" <--
"3 years ago"
"3 months ago"
"3 weeks ago"
"3 days ago"
"3 hours ago"
"3 mins ago" <--
"3 secs ago" <--

Signature · 2 lines
.marius [@trolltech.com]
'if you know what you're doing, it's not research'
#8 lore raw
Quoted 6 lines · Marius Storm-Olsen
Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

And using shorter names for the units would be a no-go?

"3y 2m ago" <--

Personally I think that looks terrible. But I recognize that it is very subjective. The only objective thing I can say is that "m" is not a unique prefix of a time unit, due to "minutes". Yes, it is obvious if you see the "y" first, but I actually parse the relative time backwards in my head and think "2 minutes ago, oh wait, 3 years, that must be months".

-Peff

#9 lore raw

Jeff King said the following on 24.02.2009 06:04:

Quoted 5 lines · Marius Storm-Olsen
Quoted 4 lines
Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

And using shorter names for the units would be a no-go?

Quoted 7 lines
Quoted 1 line

"3y 2m ago" <--

Personally I think that looks terrible. But I recognize that it is very subjective. The only objective thing I can say is that "m" is not a unique prefix of a time unit, due to "minutes". Yes, it is
obvious if you see the "y" first, but I actually parse the relative
time backwards in my head and think "2 minutes ago, oh wait, 3
years, that must be months".

Ok, the standard abbreviation for month is "mo.", so

"3y 2mo. ago"

then? ;-)

Signature · 2 lines
.marius [@trolltech.com]
'if you know what you're doing, it's not research'
#10 lore raw
Quoted 5 lines · Marius Storm-Olsen

Ok, the standard abbreviation for month is "mo.", so

"3y 2mo. ago"

then? ;-)

That is definitely better, but see the patch I just posted elsewhere in the thread.

-Peff

#11 lore raw
In reply to Jeff King
Quoted 10 lines · Jeff King

I thought about that, but I wanted to keep the maximum size down for column output (like in git-blame). Which is why I bumped the "use months" limit to 24 months instead of 12.

And that limit can also be tweaked. Surely at some point there is a range where you no longer care about the months and "N years" has high enough resolution. But there is also a point where "N months" gets cumbersome (75 months is a more annoying than "around 6 years"). The question is whether we reach the "cumbersome" point before we reach the "don't care about months" point.

Yes, "75 months" is unacceptable. I suspect people's mind would not work well with anything larger than 60 months. I've actually thought about "don't care about months" point, but 12 months is a long time. You certainly remember there still was a noticeable maturity difference between classmates who were born in the earliest months of the school year and in the last months before graduating grade school. Perhaps after 20 years.

Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

But I do not think people think of years in terms of decimal fraction.

#12 lore raw
Quoted 7 lines · Junio C Hamano

Yes, "75 months" is unacceptable. I suspect people's mind would not work well with anything larger than 60 months. I've actually thought about "don't care about months" point, but 12 months is a long time. You certainly remember there still was a noticeable maturity difference between classmates who were born in the earliest months of the school year and in the last months before graduating grade school. Perhaps after 20 years.

I'm not sure human and code development necessarily follow the same timelines. Git wouldn't even be in kindergarten yet. ;)

Quoted 4 lines
Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

But I do not think people think of years in terms of decimal fraction.

I think decimal fraction is overkill. Halves or quarters are more reasonable.

But after sleeping on it, I think "Y years, M months" is not that bad. So here is a patch (Eugene, note that this conflicts with your "fall back to DATE_SHORT" patch).

-- >8 --
Subject: [PATCH] never fallback relative times to absolute

Previously, for dates older than 12 months we fell back to just giving the absolute time. This can be a bit jarring when reading a list of times. Instead, let's switch to "Y years, M months" for five years, and then just "Y years" after that.

No particular reason on the 5 year cutoff except that it seemed reasonable to me.

---
Please feel free to mark the 5 years up to 20, or whatever you think is appropriate.

I think this should produce good output in all cases. There are a surprising number of corner cases, and I spent an embarrassing amount of time looking at the output of "git log --pretty=tformat:'%ai / %ar'".

You could also argue for splitting this into "support N years, M months" and then still fall back to absolute time eventually (whether DATE_SHORT or not).

 date.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
date.c +19 -1
index d75dff4..1165d30 100644
@@ -133,7 +133,25 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 			snprintf(timebuf, sizeof(timebuf), "%lu months ago", (diff + 15) / 30);
 			return timebuf;
 		}
-		/* Else fall back on absolute format.. */
+		/* Give years and months for 5 years or so */
+		if (diff < 1825) {
+			unsigned long years = (diff + 183) / 365;
+			unsigned long months = (diff % 365 + 15) / 30;
+			int n;
+			n = snprintf(timebuf, sizeof(timebuf), "%lu year%s",
+					years, (years > 1 ? "s" : ""));
+			if (months)
+				snprintf(timebuf + n, sizeof(timebuf) - n,
+					", %lu month%s ago",
+					months, (months > 1 ? "s" : ""));
+			else
+				snprintf(timebuf + n, sizeof(timebuf) - n,
+					" ago");
+			return timebuf;
+		}
+		/* Otherwise, just years. Centuries is probably overkill. */
+		snprintf(timebuf, sizeof(timebuf), "%lu years ago", (diff + 183) / 365);
+		return timebuf;
 	}
 
 	if (mode == DATE_LOCAL)
Signature · 1 line
1.6.2.rc1.269.ga7d41
#13 lore raw
Quoted 16 lines · Jeff King
Quoted 7 lines · Junio C Hamano

Yes, "75 months" is unacceptable. I suspect people's mind would not work well with anything larger than 60 months. I've actually thought about "don't care about months" point, but 12 months is a long time. You certainly remember there still was a noticeable maturity difference between classmates who were born in the earliest months of the school year and in the last months before graduating grade school. Perhaps after 20 years.

I'm not sure human and code development necessarily follow the same timelines. Git wouldn't even be in kindergarten yet. ;)

Quoted 3 lines
Quoted 2 lines

Another option would to give higher resolution in number of years, like "3.5 years" or even "3.1 years".

Quoted 6 lines
Quoted 1 line

But I do not think people think of years in terms of decimal fraction.

I think decimal fraction is overkill. Halves or quarters are more reasonable.

But after sleeping on it, I think "Y years, M months" is not that bad.

That was what I thought. There may be some very convincing reasoning I am not seeing in the proposals to make it ultra-short like "Y yr M mo" or "Y.x years" (i.e. "we _have_ to keep it under N characters"threshold), but I doubt there is a particular place "Y years, M months" would make the output too long to be acceptable.

#14 lore raw
Quoted 5 lines · Junio C Hamano

That was what I thought. There may be some very convincing reasoning I am not seeing in the proposals to make it ultra-short like "Y yr M mo" or "Y.x years" (i.e. "we _have_ to keep it under N characters"threshold), but I doubt there is a particular place "Y years, M months" would make the output too long to be acceptable.

Yeah, anything like blame that deals with arbitrary date formats has to know how to handle at least

strlen("Sun Feb 22 15:08:25 2009 -0500") = 30

anyway. Even the default blame format is:

strlen("2009-02-24 02:03:25 -0500") = 25

So "Y years, M months ago" is at least that short for the next ten thousand years. I can live with setting the cutoff to just "years" somewhere lower than 10,000. :)

-Peff