git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Relative timestamps in git log

From
Junio C Hamano <junkio@cox.net>
Date
Aug 27, 2006, 01:22 UTC
Message-ID
<7vodu7yntn.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0608261537120.11811@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
> The exact cut-off points when it switches from days to weeks etc are 
> totally arbitrary, but are picked somewhat to avoid the "1 weeks ago" 
> thing (by making it show "10 days ago" rather than "1 week", or "70 
> minutes ago" rather than "1 hour ago").
It might be arbitrary but I agree they make sense.  

The code was quite confusing in that after you turn it into days you stop converting to larger scale and I was going to nitpick that 365 weeks do not make much sense. I think you meant to do a "Turn it into weeks" conversion before comparing diff with 53 and then changed your mind, got confused yourself that diff is still in days and decided to say "months" for the past year.

IOW, I think there is a bug around weeks/months code ;-). On top of your patch how about the attached?

Personally I have mixed feeling about "months" scale. On one hand, I think it could extend to 30 months or so without losing readability when one is interested in "how long ago did this happen". On the other hand, it would take more time for me if I see "this happened 5 months ago" than "this happened in March this year" to recollect what the context of the particular change was ("ah I needed that feature when I was preparing the committer/author graph for OLS paper deadline").

P.S. welcome back to the list.
diff --git a/date.c b/date.c
index 92e3f6e..914fd82 100644
--- a/date.c
+++ b/date.c
@@ -87,17 +87,19 @@ const char *show_date(unsigned long time
 			snprintf(timebuf, sizeof(timebuf), "%lu hours ago", diff);
 			return timebuf;
 		}
-		/* Turn it into days */
+		/* Turn it into days; from here on we deal with days */
 		diff = (diff + 12) / 24;
 		if (diff < 14) {
 			snprintf(timebuf, sizeof(timebuf), "%lu days ago", diff);
 			return timebuf;
 		}
-		if (diff < 53) {
+		/* Say weeks for the past 6 months or so */
+		if (diff < 180) {
 			snprintf(timebuf, sizeof(timebuf), "%lu weeks ago", (diff + 3) / 7);
 			return timebuf;
 		}
-		if (diff < 365) {
+		/* Say months for the past 30 months or so */
+		if (diff < 912) {
 			snprintf(timebuf, sizeof(timebuf), "%lu months ago", (diff + 15) / 30);
 			return timebuf;
 		}
Previous: Linus Torvalds
Message 2 of 2 in “Relative timestamps in git log”
  1. Linus TorvaldsAug 26, 2006
  2. Junio C HamanoAug 27, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.