git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Can show relative date of the commit with future timestamp
@ 2012-07-05 16:18 Tom Xue
  2012-07-05 17:26 ` Junio C Hamano
  2012-08-16 23:02 ` [PATCH 0/2] relative future date Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Tom Xue @ 2012-07-05 16:18 UTC (permalink / raw)
  To: git, gitster; +Cc: Tom Xue

---
 date.c | 186 ++++++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 125 insertions(+), 61 deletions(-)

diff --git a/date.c b/date.c
index 1fdcf7c..f1ed2ba 100644
--- a/date.c
+++ b/date.c
@@ -92,72 +92,136 @@ void show_date_relative(unsigned long time, int tz,
 {
 	unsigned long diff;
 	if (now->tv_sec < time) {
-		strbuf_addstr(timebuf, _("in the future"));
-		return;
-	}
-	diff = now->tv_sec - time;
-	if (diff < 90) {
-		strbuf_addf(timebuf,
-			 Q_("%lu second ago", "%lu seconds ago", diff), diff);
-		return;
-	}
-	/* Turn it into minutes */
-	diff = (diff + 30) / 60;
-	if (diff < 90) {
-		strbuf_addf(timebuf,
-			 Q_("%lu minute ago", "%lu minutes ago", diff), diff);
-		return;
-	}
-	/* Turn it into hours */
-	diff = (diff + 30) / 60;
-	if (diff < 36) {
-		strbuf_addf(timebuf,
-			 Q_("%lu hour ago", "%lu hours ago", diff), diff);
-		return;
-	}
-	/* We deal with number of days from here on */
-	diff = (diff + 12) / 24;
-	if (diff < 14) {
-		strbuf_addf(timebuf,
-			 Q_("%lu day ago", "%lu days ago", diff), diff);
-		return;
-	}
-	/* Say weeks for the past 10 weeks or so */
-	if (diff < 70) {
-		strbuf_addf(timebuf,
-			 Q_("%lu week ago", "%lu weeks ago", (diff + 3) / 7),
-			 (diff + 3) / 7);
-		return;
-	}
-	/* Say months for the past 12 months or so */
-	if (diff < 365) {
+		strbuf_addstr(timebuf, _("in the future: "));
+		diff = time - now->tv_sec;
+		if (diff < 90) {
+			strbuf_addf(timebuf,
+				 Q_("%lu second later", "%lu seconds later", diff), diff);
+			return;
+		}
+		/* Turn it into minutes */
+		diff = (diff + 30) / 60;
+		if (diff < 90) {
+			strbuf_addf(timebuf,
+				 Q_("%lu minute later", "%lu minutes later", diff), diff);
+			return;
+		}
+		/* Turn it into hours */
+		diff = (diff + 30) / 60;
+		if (diff < 36) {
+			strbuf_addf(timebuf,
+				 Q_("%lu hour later", "%lu hours later", diff), diff);
+			return;
+		}
+		/* We deal with number of days from here on */
+		diff = (diff + 12) / 24;
+		if (diff < 14) {
+			strbuf_addf(timebuf,
+				 Q_("%lu day later", "%lu days later", diff), diff);
+			return;
+		}
+		/* Say weeks for the past 10 weeks or so */
+		if (diff < 70) {
+			strbuf_addf(timebuf,
+				 Q_("%lu week later", "%lu weeks later", (diff + 3) / 7),
+				 (diff + 3) / 7);
+			return;
+		}
+		/* Say months for the past 12 months or so */
+		if (diff < 365) {
+			strbuf_addf(timebuf,
+				 Q_("%lu month later", "%lu months later", (diff + 15) / 30),
+				 (diff + 15) / 30);
+			return;
+		}
+		/* Give years and months for 5 years or so */
+		if (diff < 1825) {
+			unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
+			unsigned long years = totalmonths / 12;
+			unsigned long months = totalmonths % 12;
+			if (months) {
+				struct strbuf sb = STRBUF_INIT;
+				strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
+				/* TRANSLATORS: "%s" is "<n> years" */
+				strbuf_addf(timebuf,
+					 Q_("%s, %lu month later", "%s, %lu months later", months),
+					 sb.buf, months);
+				strbuf_release(&sb);
+			} else
+				strbuf_addf(timebuf,
+					 Q_("%lu year later", "%lu years later", years), years);
+			return;
+		}
+		/* Otherwise, just years. Centuries is probably overkill. */
 		strbuf_addf(timebuf,
-			 Q_("%lu month ago", "%lu months ago", (diff + 15) / 30),
-			 (diff + 15) / 30);
-		return;
+			 Q_("%lu year later", "%lu years later", (diff + 183) / 365),
+			 (diff + 183) / 365);
 	}
-	/* Give years and months for 5 years or so */
-	if (diff < 1825) {
-		unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
-		unsigned long years = totalmonths / 12;
-		unsigned long months = totalmonths % 12;
-		if (months) {
-			struct strbuf sb = STRBUF_INIT;
-			strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
-			/* TRANSLATORS: "%s" is "<n> years" */
+	else {
+		diff = now->tv_sec - time;
+		if (diff < 90) {
+			strbuf_addf(timebuf,
+				 Q_("%lu second ago", "%lu seconds ago", diff), diff);
+			return;
+		}
+		/* Turn it into minutes */
+		diff = (diff + 30) / 60;
+		if (diff < 90) {
+			strbuf_addf(timebuf,
+				 Q_("%lu minute ago", "%lu minutes ago", diff), diff);
+			return;
+		}
+		/* Turn it into hours */
+		diff = (diff + 30) / 60;
+		if (diff < 36) {
 			strbuf_addf(timebuf,
-				 Q_("%s, %lu month ago", "%s, %lu months ago", months),
-				 sb.buf, months);
-			strbuf_release(&sb);
-		} else
+				 Q_("%lu hour ago", "%lu hours ago", diff), diff);
+			return;
+		}
+		/* We deal with number of days from here on */
+		diff = (diff + 12) / 24;
+		if (diff < 14) {
 			strbuf_addf(timebuf,
-				 Q_("%lu year ago", "%lu years ago", years), years);
-		return;
+				 Q_("%lu day ago", "%lu days ago", diff), diff);
+			return;
+		}
+		/* Say weeks for the past 10 weeks or so */
+		if (diff < 70) {
+			strbuf_addf(timebuf,
+				 Q_("%lu week ago", "%lu weeks ago", (diff + 3) / 7),
+				 (diff + 3) / 7);
+			return;
+		}
+		/* Say months for the past 12 months or so */
+		if (diff < 365) {
+			strbuf_addf(timebuf,
+				 Q_("%lu month ago", "%lu months ago", (diff + 15) / 30),
+				 (diff + 15) / 30);
+			return;
+		}
+		/* Give years and months for 5 years or so */
+		if (diff < 1825) {
+			unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
+			unsigned long years = totalmonths / 12;
+			unsigned long months = totalmonths % 12;
+			if (months) {
+				struct strbuf sb = STRBUF_INIT;
+				strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
+				/* TRANSLATORS: "%s" is "<n> years" */
+				strbuf_addf(timebuf,
+					 Q_("%s, %lu month ago", "%s, %lu months ago", months),
+					 sb.buf, months);
+				strbuf_release(&sb);
+			} else
+				strbuf_addf(timebuf,
+					 Q_("%lu year ago", "%lu years ago", years), years);
+			return;
+		}
+		/* Otherwise, just years. Centuries is probably overkill. */
+		strbuf_addf(timebuf,
+			 Q_("%lu year ago", "%lu years ago", (diff + 183) / 365),
+			 (diff + 183) / 365);
 	}
-	/* Otherwise, just years. Centuries is probably overkill. */
-	strbuf_addf(timebuf,
-		 Q_("%lu year ago", "%lu years ago", (diff + 183) / 365),
-		 (diff + 183) / 365);
 }
 
 const char *show_date(unsigned long time, int tz, enum date_mode mode)
-- 
1.7.11.GIT

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Can show relative date of the commit with future timestamp
  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-08-16 23:02 ` [PATCH 0/2] relative future date Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2012-07-05 17:26 UTC (permalink / raw)
  To: Tom Xue; +Cc: git

Tom Xue <tomxue0126@gmail.com> writes:

> ---
>  date.c | 186 ++++++++++++++++++++++++++++++++++++++++++++---------------------
>  1 file changed, 125 insertions(+), 61 deletions(-)

WHY?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Can show relative date of the commit with future timestamp
       [not found]   ` <CA+P7oHuCbeJ5shfL5OVhSypgygzmQwn-RGPD8UvFUFuqnoV9fA@mail.gmail.com>
@ 2012-07-06  8:15     ` Jundong Xue
  2012-08-20 22:51       ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jundong Xue @ 2012-07-06  8:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

I find an interesting and useful usage of git: todo/timeline.
For this purpose I just make a git repo and all the commits with
specified timestamp: some in the past, e.g. the date I was born; some
in the future, e.g. todo list.

I config my ~/.gitconfig as below:
[alias]
    lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset)
- %C(bold green)(%cr)%C(reset) %C(green)%s%C(reset) %C(bold white)―
%cn%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit
--date=relative
    lg = !"git lg1"
    todo = !"git lg" | grep future | grep --color -E
'future|days|hours|minutes|seconds'

tomxue@ubuntu:~/mycode/life$ git todo
* d768da9 - (in the future: 3 hours later) Meeting with vendor ― Tom
Xue (HEAD, master)
* 5fcd556 - (in the future: 12 days later) Take my personal holiday ― Tom Xue
* 9dd280b - (in the future: 11 months later) 端午节 ― Tom Xue
* 4680099 - (in the future: 9 months later) 清明节 ― Tom Xue
* 59d5266 - (in the future: 8 months later) 元宵节 ― Tom Xue
* b5308da - (in the future: 7 months later) 除夕 ― Tom Xue
* 3fe2e71 - (in the future: 4 months later) 重阳节 ― Tom Xue
* 4fad90c - (in the future: 3 months later) 中秋 ― Tom Xue
* 3dfec58 - (in the future: 7 weeks later) 七夕 ― Tom Xue
* f547a6e - (in the future: 7 months later) 我的阴历生日: 12-18 ― Tom Xue
* 5d4d240 - (in the future: 7 months later) 我的阳历生日 ― Tom Xue
* 5b165e7 - (in the future: 9 months later) Father阴历生日: 阴历3-6 ― Tom Xue
* 7b73d53 - (in the future: 10 months later) Father阳历生日 ― Tom Xue
* b6cd036 - (in the future: 6 months later) Mother阴历生日: 阴历11-23 ― Tom Xue
* 97c5163 - (in the future: 6 months later) Mother阳历生日 ― Tom Xue
* f96843c - (in the future: 5 months later) Brother阴历生日: 阴历11-4 ― Tom Xue
* c4a5432 - (in the future: 5 months later) Brother阳历生日 ― Tom Xue
* e1bfba1 - (in the future: 4 months later) Afei阳历生日 ― Tom Xue
* b551e6c - (in the future: 4 months later) Afei阴历生日: 阴历9-25 ― Tom Xue
* 0d7e644 - (in the future: 7 weeks later) 家人来京计划启动 ― Tom Xue
* 6e7ba31 - (in the future: 10 months later) Mother's day: 2nd
Sunday@May ― Tom Xue
* 4fc7701 - (in the future: 12 months later) Father's day: 3rd
Sunday@June ― Tom Xue
* 69a582e - (in the future: 10 months later) Dropbox 100G deadline ― Tom Xue

And I take a screenshot of it, which is colorful and more impressive
FYI. The link is below.
https://www.box.com/s/84b9cf402ea9419c7fe2

The link is just a picture and safe.

Except that, I think to give some accurate relative date of future
timestamp commit is also not bad.
If I make this kind of commit, I hope not only to see "in the future",
but also to see "how long/far in the future".

BR,
Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 0/2] relative future date
  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
@ 2012-08-16 23:02 ` 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   ` [PATCH 2/2] date: show relative dates in the future Junio C Hamano
  1 sibling, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-16 23:02 UTC (permalink / raw)
  To: git; +Cc: Tom Xue

Jundong Xue <tomxue0126@gmail.com> writes:

> tomxue@ubuntu:~/mycode/life$ git todo
> * d768da9 - (in the future: 3 hours later) Meeting with vendor
> * 5fcd556 - (in the future: 12 days later) Take my personal ho
> * 9dd280b - (in the future: 11 months later)
> * 4680099 - (in the future: 9 months later)
> * 59d5266 - (in the future: 8 months later)
> * b5308da - (in the future: 7 months later)
> ...

I was re-reading the backlog and after looking at it again, I do not
think what the patch tries to do is a bad thing per-se.  There are
changes I want to see _how_ it is done, though.

Especially, the duplication of the exact same logic in the future
and in the past was an unmaintainable mess.

Here is an attempt to clean it up.

Opinions?  If the list finds this is a worthwhile thing to do (I am
neutral), it needs help from i18n people to mark format messages up
properly again.

Thanks.

Junio C Hamano (2):
  date: refactor the relative date logic from presentation
  date: show relative dates in the future

 date.c          | 187 +++++++++++++++++++++++++++++++++++++++++++-------------
 t/t0006-date.sh |   2 +
 2 files changed, 146 insertions(+), 43 deletions(-)

-- 
1.7.12.rc3.69.gaf0166d

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] date: refactor the relative date logic from presentation
  2012-08-16 23:02 ` [PATCH 0/2] relative future date Junio C Hamano
@ 2012-08-16 23:02   ` Junio C Hamano
  2012-08-16 23:02   ` [PATCH 2/2] date: show relative dates in the future Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-16 23:02 UTC (permalink / raw)
  To: git; +Cc: Tom Xue, Ævar Arnfjörð Bjarmason, Thomas Rast,
	Jiang Xin

Separate the logic to decide which presentation (e.g. "N months") to
use based on the length of the time from the present and actual
presentation (i.e. "strbuf_addf()").  This is not strictly needed
but will make the next step easier to read.

The format strings lost N_() markings along the way; help from the
i18n folks to come up with the best and sane way to mark them up is
very much appreciated.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 date.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 127 insertions(+), 43 deletions(-)

diff --git a/date.c b/date.c
index 57331ed..b6ff04e 100644
--- a/date.c
+++ b/date.c
@@ -86,78 +86,162 @@ static int local_tzoffset(unsigned long time)
 	return offset * eastwest;
 }
 
-void show_date_relative(unsigned long time, int tz,
-			       const struct timeval *now,
-			       struct strbuf *timebuf)
+enum relative_style {
+	rd_seconds = 0, rd_minutes, rd_hours, rd_days, rd_weeks, rd_months, rd_years
+};
+
+struct relative_date {
+	int seconds;
+	int minutes;
+	int hours;
+	int days;
+	int weeks;
+	int months;
+	int years;
+};
+
+static enum relative_style format_relative_date(unsigned long diff,
+						struct relative_date *rd)
 {
-	unsigned long diff;
-	if (now->tv_sec < time) {
-		strbuf_addstr(timebuf, _("in the future"));
-		return;
-	}
-	diff = now->tv_sec - time;
+	memset(rd, 0, sizeof(*rd));
 	if (diff < 90) {
-		strbuf_addf(timebuf,
-			 Q_("%lu second ago", "%lu seconds ago", diff), diff);
-		return;
+		rd->seconds = diff;
+		return rd_seconds;
 	}
 	/* Turn it into minutes */
 	diff = (diff + 30) / 60;
 	if (diff < 90) {
-		strbuf_addf(timebuf,
-			 Q_("%lu minute ago", "%lu minutes ago", diff), diff);
-		return;
+		rd->minutes = diff;
+		return rd_minutes;
 	}
 	/* Turn it into hours */
 	diff = (diff + 30) / 60;
 	if (diff < 36) {
-		strbuf_addf(timebuf,
-			 Q_("%lu hour ago", "%lu hours ago", diff), diff);
-		return;
+		rd->hours = diff;
+		return rd_hours;
 	}
 	/* We deal with number of days from here on */
 	diff = (diff + 12) / 24;
 	if (diff < 14) {
-		strbuf_addf(timebuf,
-			 Q_("%lu day ago", "%lu days ago", diff), diff);
-		return;
+		rd->days = diff;
+		return rd_days;
 	}
 	/* Say weeks for the past 10 weeks or so */
 	if (diff < 70) {
-		strbuf_addf(timebuf,
-			 Q_("%lu week ago", "%lu weeks ago", (diff + 3) / 7),
-			 (diff + 3) / 7);
-		return;
+		rd->weeks = (diff + 3) / 7;
+		return rd_weeks;
 	}
 	/* Say months for the past 12 months or so */
 	if (diff < 365) {
-		strbuf_addf(timebuf,
-			 Q_("%lu month ago", "%lu months ago", (diff + 15) / 30),
-			 (diff + 15) / 30);
-		return;
+		rd->months = (diff + 15) / 30;
+		return rd_months;
 	}
 	/* Give years and months for 5 years or so */
 	if (diff < 1825) {
 		unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
-		unsigned long years = totalmonths / 12;
-		unsigned long months = totalmonths % 12;
-		if (months) {
+		rd->years = totalmonths / 12;
+		rd->months = totalmonths % 12;
+		return rd_years;
+	}
+	/* Otherwise, just years. Centuries is probably overkill. */
+	rd->years = (diff + 183) / 365;
+	return rd_years;
+}
+
+void show_date_relative(unsigned long time, int tz,
+			       const struct timeval *now,
+			       struct strbuf *timebuf)
+{
+	unsigned long diff;
+	struct relative_date rd;
+	int pf = 0; /* past or future */
+
+	struct {
+		struct { const char *s, *p; } msg_seconds;
+		struct { const char *s, *p; } msg_minutes;
+		struct { const char *s, *p; } msg_hours;
+		struct { const char *s, *p; } msg_days;
+		struct { const char *s, *p; } msg_weeks;
+		struct { const char *s, *p; } msg_months;
+		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] = {
+		{
+			{ "%lu second ago", "%lu seconds ago" },
+			{ "%lu minute ago", "%lu minutes ago" },
+			{ "%lu hour ago", "%lu hours ago" },
+			{ "%lu day ago", "%lu days ago" },
+			{ "%lu week ago", "%lu weeks ago" },
+			{ "%lu month ago", "%lu months ago" },
+			{ "%lu year", "%lu years" },
+			{
+				/* TRANSLATORS: "%s" is "<n> years" */
+				"%s, %lu month ago",
+				/* TRANSLATORS: "%s" is "<n> years" */
+				"%s, %lu months ago"
+			},
+			{ "%lu year ago", "%lu years ago" },
+		}
+	};
+
+	if (now->tv_sec < time) {
+		strbuf_addstr(timebuf, _("in the future"));
+		return;
+	}
+	diff = now->tv_sec - time;
+
+	switch (format_relative_date(diff, &rd)) {
+	case rd_seconds:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_seconds.s, msg[pf].msg_seconds.p,
+			       rd.seconds), rd.seconds);
+		break;
+	case rd_minutes:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_minutes.s, msg[pf].msg_minutes.p,
+			       rd.minutes), rd.minutes);
+		break;
+	case rd_hours:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_hours.s, msg[pf].msg_hours.p,
+			       rd.hours), rd.hours);
+		break;
+	case rd_days:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_days.s, msg[pf].msg_days.p,
+			       rd.days), rd.days);
+		break;
+	case rd_weeks:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_weeks.s, msg[pf].msg_weeks.p,
+			       rd.weeks), rd.weeks);
+		break;
+	case rd_months:
+		strbuf_addf(timebuf,
+			    Q_(msg[pf].msg_months.s, msg[pf].msg_months.p,
+			       rd.months), rd.months);
+		break;
+
+	case rd_years:
+		if (rd.months) {
 			struct strbuf sb = STRBUF_INIT;
-			strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
-			/* TRANSLATORS: "%s" is "<n> years" */
+			strbuf_addf(&sb, Q_(msg[pf].msg_years_only.s,
+					    msg[pf].msg_years_only.p,
+					    rd.years), rd.years);
 			strbuf_addf(timebuf,
-				 Q_("%s, %lu month ago", "%s, %lu months ago", months),
-				 sb.buf, months);
+				    Q_(msg[pf].msg_years_months.s,
+				       msg[pf].msg_years_months.p,
+				       rd.months),
+				    sb.buf, rd.months);
 			strbuf_release(&sb);
-		} else
+		} else {
 			strbuf_addf(timebuf,
-				 Q_("%lu year ago", "%lu years ago", years), years);
-		return;
+				    Q_(msg[pf].msg_years.s, msg[pf].msg_years.p,
+				       rd.years), rd.years);
+		}
+		break;
 	}
-	/* Otherwise, just years. Centuries is probably overkill. */
-	strbuf_addf(timebuf,
-		 Q_("%lu year ago", "%lu years ago", (diff + 183) / 365),
-		 (diff + 183) / 365);
 }
 
 const char *show_date(unsigned long time, int tz, enum date_mode mode)
-- 
1.7.12.rc3.69.gaf0166d

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] date: show relative dates in the future
  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
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-16 23:02 UTC (permalink / raw)
  To: git; +Cc: Tom Xue

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Can show relative date of the commit with future timestamp
  2012-07-06  8:15     ` Jundong Xue
@ 2012-08-20 22:51       ` Junio C Hamano
  2012-08-21  9:17         ` Jundong Xue
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2012-08-20 22:51 UTC (permalink / raw)
  To: Jundong Xue; +Cc: git

Jundong Xue <tomxue0126@gmail.com> writes:

> tomxue@ubuntu:~/mycode/life$ git todo
> * d768da9 - (in the future: 3 hours later) Meeting with vendor — Tom
> Xue (HEAD, master)
> * 5fcd556 - (in the future: 12 days later) Take my personal holiday — Tom Xue
> * 9dd280b - (in the future: 11 months later) 端午节 — Tom Xue
> * 4680099 - (in the future: 9 months later) 清明节 — Tom Xue
> * 59d5266 - (in the future: 8 months later) 元宵节 — Tom Xue
> * b5308da - (in the future: 7 months later) 除夕 — Tom Xue
> ...

I was re-reading the backlog and after looking at it again, I do not
think what the patch tries to do is a bad thing.  There are changes
I want to see _how_ it is done, though.

Especially, the duplication of the exact same logic in the future
and in the past is an unmaintainable mess.

I have queued a replacement in 'pu'.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Can show relative date of the commit with future timestamp
  2012-08-20 22:51       ` Junio C Hamano
@ 2012-08-21  9:17         ` Jundong Xue
  0 siblings, 0 replies; 8+ messages in thread
From: Jundong Xue @ 2012-08-21  9:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Thank you for reconsider my patch! As you said, my implementation is
not good while the idea is not bad.
I checked out the latest git source code and patch it with your
replacement, and it looks nice, I like it.

This patch comes from my real need. And I think someone may need it as
well. To be honest, this is my first submitted patch in my life.


On Tue, Aug 21, 2012 at 6:51 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jundong Xue <tomxue0126@gmail.com> writes:
>
>> tomxue@ubuntu:~/mycode/life$ git todo
>> * d768da9 - (in the future: 3 hours later) Meeting with vendor ― Tom
>> Xue (HEAD, master)
>> * 5fcd556 - (in the future: 12 days later) Take my personal holiday ― Tom Xue
>> * 9dd280b - (in the future: 11 months later) 端午节 ― Tom Xue
>> * 4680099 - (in the future: 9 months later) 清明节 ― Tom Xue
>> * 59d5266 - (in the future: 8 months later) 元宵节 ― Tom Xue
>> * b5308da - (in the future: 7 months later) 除夕 ― Tom Xue
>> ...
>
> I was re-reading the backlog and after looking at it again, I do not
> think what the patch tries to do is a bad thing.  There are changes
> I want to see _how_ it is done, though.
>
> Especially, the duplication of the exact same logic in the future
> and in the past is an unmaintainable mess.
>
> I have queued a replacement in 'pu'.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-21  9:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` [PATCH 2/2] date: show relative dates in the future Junio C Hamano

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).