git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Tom Xue <tomxue0126@gmail.com>
Subject: [PATCH 2/2] date: show relative dates in the future
Date: Thu, 16 Aug 2012 16:02:03 -0700	[thread overview]
Message-ID: <1345158123-22189-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1345158123-22189-1-git-send-email-gitster@pobox.com>

Inspired by an earlier patch on the list by Tom Xue, but I think
this is done in a much more maintainable way.

It still remains to be seen if this feature makes sense, though.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 date.c          | 27 ++++++++++++++++++++++-----
 t/t0006-date.sh |  2 ++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/date.c b/date.c
index b6ff04e..f897955 100644
--- a/date.c
+++ b/date.c
@@ -166,7 +166,7 @@ void show_date_relative(unsigned long time, int tz,
 		struct { const char *s, *p; } msg_years_only;
 		struct { const char *s, *p; } msg_years_months;
 		struct { const char *s, *p; } msg_years;
-	} msg[1] = {
+	} msg[2] = {
 		{
 			{ "%lu second ago", "%lu seconds ago" },
 			{ "%lu minute ago", "%lu minutes ago" },
@@ -182,14 +182,31 @@ void show_date_relative(unsigned long time, int tz,
 				"%s, %lu months ago"
 			},
 			{ "%lu year ago", "%lu years ago" },
-		}
+		},
+		{
+			{ "%lu second in the future", "%lu seconds in the future" },
+			{ "%lu minute in the future", "%lu minutes in the future" },
+			{ "%lu hour in the future", "%lu hours in the future" },
+			{ "%lu day in the future", "%lu days in the future" },
+			{ "%lu week in the future", "%lu weeks in the future" },
+			{ "%lu month in the future", "%lu months in the future" },
+			{ "%lu year", "%lu years" },
+			{
+				/* TRANSLATORS: "%s" is "<n> years" */
+				"%s, %lu month in the future",
+				/* TRANSLATORS: "%s" is "<n> years" */
+				"%s, %lu months in the future"
+			},
+			{ "%lu year in the future", "%lu years in the future" },
+		},
 	};
 
 	if (now->tv_sec < time) {
-		strbuf_addstr(timebuf, _("in the future"));
-		return;
+		diff = time - now->tv_sec;
+		pf = 1; /* in the future */
+	} else {
+		diff = now->tv_sec - time;
 	}
-	diff = now->tv_sec - time;
 
 	switch (format_relative_date(diff, &rd)) {
 	case rd_seconds:
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 1d29810..eef932c 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -26,6 +26,8 @@ check_show 55188000 '1 year, 9 months ago'
 check_show 630000000 '20 years ago'
 check_show 31449600 '12 months ago'
 check_show 62985600 '2 years ago'
+check_show -5 '5 seconds in the future'
+check_show -55188000 '1 year, 9 months in the future'
 
 check_parse() {
 	echo "$1 -> $2" >expect
-- 
1.7.12.rc3.69.gaf0166d

      parent reply	other threads:[~2012-08-16 23:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05 16:18 [PATCH] Can show relative date of the commit with future timestamp Tom Xue
2012-07-05 17:26 ` Junio C Hamano
     [not found]   ` <CA+P7oHuCbeJ5shfL5OVhSypgygzmQwn-RGPD8UvFUFuqnoV9fA@mail.gmail.com>
2012-07-06  8:15     ` Jundong Xue
2012-08-20 22:51       ` Junio C Hamano
2012-08-21  9:17         ` Jundong Xue
2012-08-16 23:02 ` [PATCH 0/2] relative future date Junio C Hamano
2012-08-16 23:02   ` [PATCH 1/2] date: refactor the relative date logic from presentation Junio C Hamano
2012-08-16 23:02   ` Junio C Hamano [this message]

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

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

  git send-email \
    --in-reply-to=1345158123-22189-3-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=tomxue0126@gmail.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.
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 NNTP newsgroup(s).