{"thread":{"id":"30959","subject":"[PATCH] Can show relative date of the commit with future timestamp","startedAt":"2012-07-05T16:18:07Z","lastAt":"2012-08-21T09:17:30Z","messageCount":8,"participants":["Tom Xue","Junio C Hamano","Jundong Xue"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"194656","messageId":"1341505087-13632-1-git-send-email-tomxue0126@gmail.com","threadId":"30959","inReplyTo":null,"subject":"[PATCH] Can show relative date of the commit with future timestamp","fromName":"Tom Xue","fromEmail":"tomxue0126@gmail.com","sentAt":"2012-07-05T16:18:07Z","receivedAt":"2012-07-05T16:18:07Z","isPatch":true,"sender":{"key":"tomxue0126@gmail.com","avatar":"https://gravatar.com/avatar/7de5629e70cc14c4d54edd85c0088080152fe8f30b06836aa868d521a94b52d7?d=mp&s=160"},"body":"---\n date.c | 186 ++++++++++++++++++++++++++++++++++++++++++++---------------------\n 1 file changed, 125 insertions(+), 61 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex 1fdcf7c..f1ed2ba 100644\n--- a/date.c\n+++ b/date.c\n@@ -92,72 +92,136 @@ void show_date_relative(unsigned long time, int tz,\n {\n \tunsigned long diff;\n \tif (now->tv_sec < time) {\n-\t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n-\t\treturn;\n-\t}\n-\tdiff = now->tv_sec - time;\n-\tif (diff < 90) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu second ago\", \"%lu seconds ago\", diff), diff);\n-\t\treturn;\n-\t}\n-\t/* Turn it into minutes */\n-\tdiff = (diff + 30) / 60;\n-\tif (diff < 90) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu minute ago\", \"%lu minutes ago\", diff), diff);\n-\t\treturn;\n-\t}\n-\t/* Turn it into hours */\n-\tdiff = (diff + 30) / 60;\n-\tif (diff < 36) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu hour ago\", \"%lu hours ago\", diff), diff);\n-\t\treturn;\n-\t}\n-\t/* We deal with number of days from here on */\n-\tdiff = (diff + 12) / 24;\n-\tif (diff < 14) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu day ago\", \"%lu days ago\", diff), diff);\n-\t\treturn;\n-\t}\n-\t/* Say weeks for the past 10 weeks or so */\n-\tif (diff < 70) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu week ago\", \"%lu weeks ago\", (diff + 3) / 7),\n-\t\t\t (diff + 3) / 7);\n-\t\treturn;\n-\t}\n-\t/* Say months for the past 12 months or so */\n-\tif (diff < 365) {\n+\t\tstrbuf_addstr(timebuf, _(\"in the future: \"));\n+\t\tdiff = time - now->tv_sec;\n+\t\tif (diff < 90) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu second later\", \"%lu seconds later\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Turn it into minutes */\n+\t\tdiff = (diff + 30) / 60;\n+\t\tif (diff < 90) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu minute later\", \"%lu minutes later\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Turn it into hours */\n+\t\tdiff = (diff + 30) / 60;\n+\t\tif (diff < 36) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu hour later\", \"%lu hours later\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* We deal with number of days from here on */\n+\t\tdiff = (diff + 12) / 24;\n+\t\tif (diff < 14) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu day later\", \"%lu days later\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Say weeks for the past 10 weeks or so */\n+\t\tif (diff < 70) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu week later\", \"%lu weeks later\", (diff + 3) / 7),\n+\t\t\t\t (diff + 3) / 7);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Say months for the past 12 months or so */\n+\t\tif (diff < 365) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu month later\", \"%lu months later\", (diff + 15) / 30),\n+\t\t\t\t (diff + 15) / 30);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Give years and months for 5 years or so */\n+\t\tif (diff < 1825) {\n+\t\t\tunsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);\n+\t\t\tunsigned long years = totalmonths / 12;\n+\t\t\tunsigned long months = totalmonths % 12;\n+\t\t\tif (months) {\n+\t\t\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\t\t\tstrbuf_addf(&sb, Q_(\"%lu year\", \"%lu years\", years), years);\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t\t Q_(\"%s, %lu month later\", \"%s, %lu months later\", months),\n+\t\t\t\t\t sb.buf, months);\n+\t\t\t\tstrbuf_release(&sb);\n+\t\t\t} else\n+\t\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t\t Q_(\"%lu year later\", \"%lu years later\", years), years);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Otherwise, just years. Centuries is probably overkill. */\n \t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu month ago\", \"%lu months ago\", (diff + 15) / 30),\n-\t\t\t (diff + 15) / 30);\n-\t\treturn;\n+\t\t\t Q_(\"%lu year later\", \"%lu years later\", (diff + 183) / 365),\n+\t\t\t (diff + 183) / 365);\n \t}\n-\t/* Give years and months for 5 years or so */\n-\tif (diff < 1825) {\n-\t\tunsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);\n-\t\tunsigned long years = totalmonths / 12;\n-\t\tunsigned long months = totalmonths % 12;\n-\t\tif (months) {\n-\t\t\tstruct strbuf sb = STRBUF_INIT;\n-\t\t\tstrbuf_addf(&sb, Q_(\"%lu year\", \"%lu years\", years), years);\n-\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\telse {\n+\t\tdiff = now->tv_sec - time;\n+\t\tif (diff < 90) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu second ago\", \"%lu seconds ago\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Turn it into minutes */\n+\t\tdiff = (diff + 30) / 60;\n+\t\tif (diff < 90) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu minute ago\", \"%lu minutes ago\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Turn it into hours */\n+\t\tdiff = (diff + 30) / 60;\n+\t\tif (diff < 36) {\n \t\t\tstrbuf_addf(timebuf,\n-\t\t\t\t Q_(\"%s, %lu month ago\", \"%s, %lu months ago\", months),\n-\t\t\t\t sb.buf, months);\n-\t\t\tstrbuf_release(&sb);\n-\t\t} else\n+\t\t\t\t Q_(\"%lu hour ago\", \"%lu hours ago\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* We deal with number of days from here on */\n+\t\tdiff = (diff + 12) / 24;\n+\t\tif (diff < 14) {\n \t\t\tstrbuf_addf(timebuf,\n-\t\t\t\t Q_(\"%lu year ago\", \"%lu years ago\", years), years);\n-\t\treturn;\n+\t\t\t\t Q_(\"%lu day ago\", \"%lu days ago\", diff), diff);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Say weeks for the past 10 weeks or so */\n+\t\tif (diff < 70) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu week ago\", \"%lu weeks ago\", (diff + 3) / 7),\n+\t\t\t\t (diff + 3) / 7);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Say months for the past 12 months or so */\n+\t\tif (diff < 365) {\n+\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t Q_(\"%lu month ago\", \"%lu months ago\", (diff + 15) / 30),\n+\t\t\t\t (diff + 15) / 30);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Give years and months for 5 years or so */\n+\t\tif (diff < 1825) {\n+\t\t\tunsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);\n+\t\t\tunsigned long years = totalmonths / 12;\n+\t\t\tunsigned long months = totalmonths % 12;\n+\t\t\tif (months) {\n+\t\t\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\t\t\tstrbuf_addf(&sb, Q_(\"%lu year\", \"%lu years\", years), years);\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t\t Q_(\"%s, %lu month ago\", \"%s, %lu months ago\", months),\n+\t\t\t\t\t sb.buf, months);\n+\t\t\t\tstrbuf_release(&sb);\n+\t\t\t} else\n+\t\t\t\tstrbuf_addf(timebuf,\n+\t\t\t\t\t Q_(\"%lu year ago\", \"%lu years ago\", years), years);\n+\t\t\treturn;\n+\t\t}\n+\t\t/* Otherwise, just years. Centuries is probably overkill. */\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t Q_(\"%lu year ago\", \"%lu years ago\", (diff + 183) / 365),\n+\t\t\t (diff + 183) / 365);\n \t}\n-\t/* Otherwise, just years. Centuries is probably overkill. */\n-\tstrbuf_addf(timebuf,\n-\t\t Q_(\"%lu year ago\", \"%lu years ago\", (diff + 183) / 365),\n-\t\t (diff + 183) / 365);\n }\n \n const char *show_date(unsigned long time, int tz, enum date_mode mode)\n-- \n1.7.11.GIT\n"},{"id":"194663","messageId":"7vy5myqftw.fsf@alter.siamese.dyndns.org","threadId":"30959","inReplyTo":"1341505087-13632-1-git-send-email-tomxue0126@gmail.com","subject":"Re: [PATCH] Can show relative date of the commit with future timestamp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-05T17:26:51Z","receivedAt":"2012-07-05T17:26:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tom Xue <tomxue0126@gmail.com> writes:\n\n> ---\n>  date.c | 186 ++++++++++++++++++++++++++++++++++++++++++++---------------------\n>  1 file changed, 125 insertions(+), 61 deletions(-)\n\nWHY?\n"},{"id":"194700","messageId":"CA+P7oHtGsBoRGsUzg4qqm7sZJ=+1Jh06Gmj1uw+k0-S9Gk+DXQ@mail.gmail.com","threadId":"30959","inReplyTo":"CA+P7oHuCbeJ5shfL5OVhSypgygzmQwn-RGPD8UvFUFuqnoV9fA@mail.gmail.com","subject":"Re: [PATCH] Can show relative date of the commit with future timestamp","fromName":"Jundong Xue","fromEmail":"tomxue0126@gmail.com","sentAt":"2012-07-06T08:15:25Z","receivedAt":"2012-07-06T08:15:25Z","isPatch":true,"sender":{"key":"tomxue0126@gmail.com","avatar":"https://gravatar.com/avatar/7de5629e70cc14c4d54edd85c0088080152fe8f30b06836aa868d521a94b52d7?d=mp&s=160"},"body":"I find an interesting and useful usage of git: todo/timeline.\nFor this purpose I just make a git repo and all the commits with\nspecified timestamp: some in the past, e.g. the date I was born; some\nin the future, e.g. todo list.\n\nI config my ~/.gitconfig as below:\n[alias]\n    lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset)\n- %C(bold green)(%cr)%C(reset) %C(green)%s%C(reset) %C(bold white)―\n%cn%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit\n--date=relative\n    lg = !\"git lg1\"\n    todo = !\"git lg\" | grep future | grep --color -E\n'future|days|hours|minutes|seconds'\n\ntomxue@ubuntu:~/mycode/life$ git todo\n* d768da9 - (in the future: 3 hours later) Meeting with vendor ― Tom\nXue (HEAD, master)\n* 5fcd556 - (in the future: 12 days later) Take my personal holiday ― Tom Xue\n* 9dd280b - (in the future: 11 months later) 端午节 ― Tom Xue\n* 4680099 - (in the future: 9 months later) 清明节 ― Tom Xue\n* 59d5266 - (in the future: 8 months later) 元宵节 ― Tom Xue\n* b5308da - (in the future: 7 months later) 除夕 ― Tom Xue\n* 3fe2e71 - (in the future: 4 months later) 重阳节 ― Tom Xue\n* 4fad90c - (in the future: 3 months later) 中秋 ― Tom Xue\n* 3dfec58 - (in the future: 7 weeks later) 七夕 ― Tom Xue\n* f547a6e - (in the future: 7 months later) 我的阴历生日: 12-18 ― Tom Xue\n* 5d4d240 - (in the future: 7 months later) 我的阳历生日 ― Tom Xue\n* 5b165e7 - (in the future: 9 months later) Father阴历生日: 阴历3-6 ― Tom Xue\n* 7b73d53 - (in the future: 10 months later) Father阳历生日 ― Tom Xue\n* b6cd036 - (in the future: 6 months later) Mother阴历生日: 阴历11-23 ― Tom Xue\n* 97c5163 - (in the future: 6 months later) Mother阳历生日 ― Tom Xue\n* f96843c - (in the future: 5 months later) Brother阴历生日: 阴历11-4 ― Tom Xue\n* c4a5432 - (in the future: 5 months later) Brother阳历生日 ― Tom Xue\n* e1bfba1 - (in the future: 4 months later) Afei阳历生日 ― Tom Xue\n* b551e6c - (in the future: 4 months later) Afei阴历生日: 阴历9-25 ― Tom Xue\n* 0d7e644 - (in the future: 7 weeks later) 家人来京计划启动 ― Tom Xue\n* 6e7ba31 - (in the future: 10 months later) Mother's day: 2nd\nSunday@May ― Tom Xue\n* 4fc7701 - (in the future: 12 months later) Father's day: 3rd\nSunday@June ― Tom Xue\n* 69a582e - (in the future: 10 months later) Dropbox 100G deadline ― Tom Xue\n\nAnd I take a screenshot of it, which is colorful and more impressive\nFYI. The link is below.\nhttps://www.box.com/s/84b9cf402ea9419c7fe2\n\nThe link is just a picture and safe.\n\nExcept that, I think to give some accurate relative date of future\ntimestamp commit is also not bad.\nIf I make this kind of commit, I hope not only to see \"in the future\",\nbut also to see \"how long/far in the future\".\n\nBR,\nTom\n"},{"id":"197130","messageId":"1345158123-22189-1-git-send-email-gitster@pobox.com","threadId":"30959","inReplyTo":"1341505087-13632-1-git-send-email-tomxue0126@gmail.com","subject":"[PATCH 0/2] relative future date","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-16T23:02:01Z","receivedAt":"2012-08-16T23:02:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jundong Xue <tomxue0126@gmail.com> writes:\n\n> tomxue@ubuntu:~/mycode/life$ git todo\n> * d768da9 - (in the future: 3 hours later) Meeting with vendor\n> * 5fcd556 - (in the future: 12 days later) Take my personal ho\n> * 9dd280b - (in the future: 11 months later)\n> * 4680099 - (in the future: 9 months later)\n> * 59d5266 - (in the future: 8 months later)\n> * b5308da - (in the future: 7 months later)\n> ...\n\nI was re-reading the backlog and after looking at it again, I do not\nthink what the patch tries to do is a bad thing per-se.  There are\nchanges I want to see _how_ it is done, though.\n\nEspecially, the duplication of the exact same logic in the future\nand in the past was an unmaintainable mess.\n\nHere is an attempt to clean it up.\n\nOpinions?  If the list finds this is a worthwhile thing to do (I am\nneutral), it needs help from i18n people to mark format messages up\nproperly again.\n\nThanks.\n\nJunio C Hamano (2):\n  date: refactor the relative date logic from presentation\n  date: show relative dates in the future\n\n date.c          | 187 +++++++++++++++++++++++++++++++++++++++++++-------------\n t/t0006-date.sh |   2 +\n 2 files changed, 146 insertions(+), 43 deletions(-)\n\n-- \n1.7.12.rc3.69.gaf0166d\n"},{"id":"197132","messageId":"1345158123-22189-2-git-send-email-gitster@pobox.com","threadId":"30959","inReplyTo":"1345158123-22189-1-git-send-email-gitster@pobox.com","subject":"[PATCH 1/2] date: refactor the relative date logic from presentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-16T23:02:02Z","receivedAt":"2012-08-16T23:02:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Separate the logic to decide which presentation (e.g. \"N months\") to\nuse based on the length of the time from the present and actual\npresentation (i.e. \"strbuf_addf()\").  This is not strictly needed\nbut will make the next step easier to read.\n\nThe format strings lost N_() markings along the way; help from the\ni18n folks to come up with the best and sane way to mark them up is\nvery much appreciated.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n date.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++-----------------\n 1 file changed, 127 insertions(+), 43 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex 57331ed..b6ff04e 100644\n--- a/date.c\n+++ b/date.c\n@@ -86,78 +86,162 @@ static int local_tzoffset(unsigned long time)\n \treturn offset * eastwest;\n }\n \n-void show_date_relative(unsigned long time, int tz,\n-\t\t\t       const struct timeval *now,\n-\t\t\t       struct strbuf *timebuf)\n+enum relative_style {\n+\trd_seconds = 0, rd_minutes, rd_hours, rd_days, rd_weeks, rd_months, rd_years\n+};\n+\n+struct relative_date {\n+\tint seconds;\n+\tint minutes;\n+\tint hours;\n+\tint days;\n+\tint weeks;\n+\tint months;\n+\tint years;\n+};\n+\n+static enum relative_style format_relative_date(unsigned long diff,\n+\t\t\t\t\t\tstruct relative_date *rd)\n {\n-\tunsigned long diff;\n-\tif (now->tv_sec < time) {\n-\t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n-\t\treturn;\n-\t}\n-\tdiff = now->tv_sec - time;\n+\tmemset(rd, 0, sizeof(*rd));\n \tif (diff < 90) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu second ago\", \"%lu seconds ago\", diff), diff);\n-\t\treturn;\n+\t\trd->seconds = diff;\n+\t\treturn rd_seconds;\n \t}\n \t/* Turn it into minutes */\n \tdiff = (diff + 30) / 60;\n \tif (diff < 90) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu minute ago\", \"%lu minutes ago\", diff), diff);\n-\t\treturn;\n+\t\trd->minutes = diff;\n+\t\treturn rd_minutes;\n \t}\n \t/* Turn it into hours */\n \tdiff = (diff + 30) / 60;\n \tif (diff < 36) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu hour ago\", \"%lu hours ago\", diff), diff);\n-\t\treturn;\n+\t\trd->hours = diff;\n+\t\treturn rd_hours;\n \t}\n \t/* We deal with number of days from here on */\n \tdiff = (diff + 12) / 24;\n \tif (diff < 14) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu day ago\", \"%lu days ago\", diff), diff);\n-\t\treturn;\n+\t\trd->days = diff;\n+\t\treturn rd_days;\n \t}\n \t/* Say weeks for the past 10 weeks or so */\n \tif (diff < 70) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu week ago\", \"%lu weeks ago\", (diff + 3) / 7),\n-\t\t\t (diff + 3) / 7);\n-\t\treturn;\n+\t\trd->weeks = (diff + 3) / 7;\n+\t\treturn rd_weeks;\n \t}\n \t/* Say months for the past 12 months or so */\n \tif (diff < 365) {\n-\t\tstrbuf_addf(timebuf,\n-\t\t\t Q_(\"%lu month ago\", \"%lu months ago\", (diff + 15) / 30),\n-\t\t\t (diff + 15) / 30);\n-\t\treturn;\n+\t\trd->months = (diff + 15) / 30;\n+\t\treturn rd_months;\n \t}\n \t/* Give years and months for 5 years or so */\n \tif (diff < 1825) {\n \t\tunsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);\n-\t\tunsigned long years = totalmonths / 12;\n-\t\tunsigned long months = totalmonths % 12;\n-\t\tif (months) {\n+\t\trd->years = totalmonths / 12;\n+\t\trd->months = totalmonths % 12;\n+\t\treturn rd_years;\n+\t}\n+\t/* Otherwise, just years. Centuries is probably overkill. */\n+\trd->years = (diff + 183) / 365;\n+\treturn rd_years;\n+}\n+\n+void show_date_relative(unsigned long time, int tz,\n+\t\t\t       const struct timeval *now,\n+\t\t\t       struct strbuf *timebuf)\n+{\n+\tunsigned long diff;\n+\tstruct relative_date rd;\n+\tint pf = 0; /* past or future */\n+\n+\tstruct {\n+\t\tstruct { const char *s, *p; } msg_seconds;\n+\t\tstruct { const char *s, *p; } msg_minutes;\n+\t\tstruct { const char *s, *p; } msg_hours;\n+\t\tstruct { const char *s, *p; } msg_days;\n+\t\tstruct { const char *s, *p; } msg_weeks;\n+\t\tstruct { const char *s, *p; } msg_months;\n+\t\tstruct { const char *s, *p; } msg_years_only;\n+\t\tstruct { const char *s, *p; } msg_years_months;\n+\t\tstruct { const char *s, *p; } msg_years;\n+\t} msg[1] = {\n+\t\t{\n+\t\t\t{ \"%lu second ago\", \"%lu seconds ago\" },\n+\t\t\t{ \"%lu minute ago\", \"%lu minutes ago\" },\n+\t\t\t{ \"%lu hour ago\", \"%lu hours ago\" },\n+\t\t\t{ \"%lu day ago\", \"%lu days ago\" },\n+\t\t\t{ \"%lu week ago\", \"%lu weeks ago\" },\n+\t\t\t{ \"%lu month ago\", \"%lu months ago\" },\n+\t\t\t{ \"%lu year\", \"%lu years\" },\n+\t\t\t{\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\t\"%s, %lu month ago\",\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\t\"%s, %lu months ago\"\n+\t\t\t},\n+\t\t\t{ \"%lu year ago\", \"%lu years ago\" },\n+\t\t}\n+\t};\n+\n+\tif (now->tv_sec < time) {\n+\t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n+\t\treturn;\n+\t}\n+\tdiff = now->tv_sec - time;\n+\n+\tswitch (format_relative_date(diff, &rd)) {\n+\tcase rd_seconds:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_seconds.s, msg[pf].msg_seconds.p,\n+\t\t\t       rd.seconds), rd.seconds);\n+\t\tbreak;\n+\tcase rd_minutes:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_minutes.s, msg[pf].msg_minutes.p,\n+\t\t\t       rd.minutes), rd.minutes);\n+\t\tbreak;\n+\tcase rd_hours:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_hours.s, msg[pf].msg_hours.p,\n+\t\t\t       rd.hours), rd.hours);\n+\t\tbreak;\n+\tcase rd_days:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_days.s, msg[pf].msg_days.p,\n+\t\t\t       rd.days), rd.days);\n+\t\tbreak;\n+\tcase rd_weeks:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_weeks.s, msg[pf].msg_weeks.p,\n+\t\t\t       rd.weeks), rd.weeks);\n+\t\tbreak;\n+\tcase rd_months:\n+\t\tstrbuf_addf(timebuf,\n+\t\t\t    Q_(msg[pf].msg_months.s, msg[pf].msg_months.p,\n+\t\t\t       rd.months), rd.months);\n+\t\tbreak;\n+\n+\tcase rd_years:\n+\t\tif (rd.months) {\n \t\t\tstruct strbuf sb = STRBUF_INIT;\n-\t\t\tstrbuf_addf(&sb, Q_(\"%lu year\", \"%lu years\", years), years);\n-\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\tstrbuf_addf(&sb, Q_(msg[pf].msg_years_only.s,\n+\t\t\t\t\t    msg[pf].msg_years_only.p,\n+\t\t\t\t\t    rd.years), rd.years);\n \t\t\tstrbuf_addf(timebuf,\n-\t\t\t\t Q_(\"%s, %lu month ago\", \"%s, %lu months ago\", months),\n-\t\t\t\t sb.buf, months);\n+\t\t\t\t    Q_(msg[pf].msg_years_months.s,\n+\t\t\t\t       msg[pf].msg_years_months.p,\n+\t\t\t\t       rd.months),\n+\t\t\t\t    sb.buf, rd.months);\n \t\t\tstrbuf_release(&sb);\n-\t\t} else\n+\t\t} else {\n \t\t\tstrbuf_addf(timebuf,\n-\t\t\t\t Q_(\"%lu year ago\", \"%lu years ago\", years), years);\n-\t\treturn;\n+\t\t\t\t    Q_(msg[pf].msg_years.s, msg[pf].msg_years.p,\n+\t\t\t\t       rd.years), rd.years);\n+\t\t}\n+\t\tbreak;\n \t}\n-\t/* Otherwise, just years. Centuries is probably overkill. */\n-\tstrbuf_addf(timebuf,\n-\t\t Q_(\"%lu year ago\", \"%lu years ago\", (diff + 183) / 365),\n-\t\t (diff + 183) / 365);\n }\n \n const char *show_date(unsigned long time, int tz, enum date_mode mode)\n-- \n1.7.12.rc3.69.gaf0166d\n"},{"id":"197131","messageId":"1345158123-22189-3-git-send-email-gitster@pobox.com","threadId":"30959","inReplyTo":"1345158123-22189-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/2] date: show relative dates in the future","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-16T23:02:03Z","receivedAt":"2012-08-16T23:02:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Inspired by an earlier patch on the list by Tom Xue, but I think\nthis is done in a much more maintainable way.\n\nIt still remains to be seen if this feature makes sense, though.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n date.c          | 27 ++++++++++++++++++++++-----\n t/t0006-date.sh |  2 ++\n 2 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex b6ff04e..f897955 100644\n--- a/date.c\n+++ b/date.c\n@@ -166,7 +166,7 @@ void show_date_relative(unsigned long time, int tz,\n \t\tstruct { const char *s, *p; } msg_years_only;\n \t\tstruct { const char *s, *p; } msg_years_months;\n \t\tstruct { const char *s, *p; } msg_years;\n-\t} msg[1] = {\n+\t} msg[2] = {\n \t\t{\n \t\t\t{ \"%lu second ago\", \"%lu seconds ago\" },\n \t\t\t{ \"%lu minute ago\", \"%lu minutes ago\" },\n@@ -182,14 +182,31 @@ void show_date_relative(unsigned long time, int tz,\n \t\t\t\t\"%s, %lu months ago\"\n \t\t\t},\n \t\t\t{ \"%lu year ago\", \"%lu years ago\" },\n-\t\t}\n+\t\t},\n+\t\t{\n+\t\t\t{ \"%lu second in the future\", \"%lu seconds in the future\" },\n+\t\t\t{ \"%lu minute in the future\", \"%lu minutes in the future\" },\n+\t\t\t{ \"%lu hour in the future\", \"%lu hours in the future\" },\n+\t\t\t{ \"%lu day in the future\", \"%lu days in the future\" },\n+\t\t\t{ \"%lu week in the future\", \"%lu weeks in the future\" },\n+\t\t\t{ \"%lu month in the future\", \"%lu months in the future\" },\n+\t\t\t{ \"%lu year\", \"%lu years\" },\n+\t\t\t{\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\t\"%s, %lu month in the future\",\n+\t\t\t\t/* TRANSLATORS: \"%s\" is \"<n> years\" */\n+\t\t\t\t\"%s, %lu months in the future\"\n+\t\t\t},\n+\t\t\t{ \"%lu year in the future\", \"%lu years in the future\" },\n+\t\t},\n \t};\n \n \tif (now->tv_sec < time) {\n-\t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n-\t\treturn;\n+\t\tdiff = time - now->tv_sec;\n+\t\tpf = 1; /* in the future */\n+\t} else {\n+\t\tdiff = now->tv_sec - time;\n \t}\n-\tdiff = now->tv_sec - time;\n \n \tswitch (format_relative_date(diff, &rd)) {\n \tcase rd_seconds:\ndiff --git a/t/t0006-date.sh b/t/t0006-date.sh\nindex 1d29810..eef932c 100755\n--- a/t/t0006-date.sh\n+++ b/t/t0006-date.sh\n@@ -26,6 +26,8 @@ check_show 55188000 '1 year, 9 months ago'\n check_show 630000000 '20 years ago'\n check_show 31449600 '12 months ago'\n check_show 62985600 '2 years ago'\n+check_show -5 '5 seconds in the future'\n+check_show -55188000 '1 year, 9 months in the future'\n \n check_parse() {\n \techo \"$1 -> $2\" >expect\n-- \n1.7.12.rc3.69.gaf0166d\n"},{"id":"197469","messageId":"7vsjbhgotj.fsf@alter.siamese.dyndns.org","threadId":"30959","inReplyTo":"CA+P7oHtGsBoRGsUzg4qqm7sZJ=+1Jh06Gmj1uw+k0-S9Gk+DXQ@mail.gmail.com","subject":"Re: [PATCH] Can show relative date of the commit with future timestamp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-20T22:51:04Z","receivedAt":"2012-08-20T22:51:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jundong Xue <tomxue0126@gmail.com> writes:\n\n> tomxue@ubuntu:~/mycode/life$ git todo\n> * d768da9 - (in the future: 3 hours later) Meeting with vendor — Tom\n> Xue (HEAD, master)\n> * 5fcd556 - (in the future: 12 days later) Take my personal holiday — Tom Xue\n> * 9dd280b - (in the future: 11 months later) 端午节 — Tom Xue\n> * 4680099 - (in the future: 9 months later) 清明节 — Tom Xue\n> * 59d5266 - (in the future: 8 months later) 元宵节 — Tom Xue\n> * b5308da - (in the future: 7 months later) 除夕 — Tom Xue\n> ...\n\nI was re-reading the backlog and after looking at it again, I do not\nthink what the patch tries to do is a bad thing.  There are changes\nI want to see _how_ it is done, though.\n\nEspecially, the duplication of the exact same logic in the future\nand in the past is an unmaintainable mess.\n\nI have queued a replacement in 'pu'.\n"},{"id":"197522","messageId":"CA+P7oHt2Vsy+UBMuEvSXeK+bhArRa=NWT1C=NO0qRS5t9gFE6Q@mail.gmail.com","threadId":"30959","inReplyTo":"7vsjbhgotj.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Can show relative date of the commit with future timestamp","fromName":"Jundong Xue","fromEmail":"tomxue0126@gmail.com","sentAt":"2012-08-21T09:17:30Z","receivedAt":"2012-08-21T09:17:30Z","isPatch":true,"sender":{"key":"tomxue0126@gmail.com","avatar":"https://gravatar.com/avatar/7de5629e70cc14c4d54edd85c0088080152fe8f30b06836aa868d521a94b52d7?d=mp&s=160"},"body":"Thank you for reconsider my patch! As you said, my implementation is\nnot good while the idea is not bad.\nI checked out the latest git source code and patch it with your\nreplacement, and it looks nice, I like it.\n\nThis patch comes from my real need. And I think someone may need it as\nwell. To be honest, this is my first submitted patch in my life.\n\n\nOn Tue, Aug 21, 2012 at 6:51 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jundong Xue <tomxue0126@gmail.com> writes:\n>\n>> tomxue@ubuntu:~/mycode/life$ git todo\n>> * d768da9 - (in the future: 3 hours later) Meeting with vendor ― Tom\n>> Xue (HEAD, master)\n>> * 5fcd556 - (in the future: 12 days later) Take my personal holiday ― Tom Xue\n>> * 9dd280b - (in the future: 11 months later) 端午节 ― Tom Xue\n>> * 4680099 - (in the future: 9 months later) 清明节 ― Tom Xue\n>> * 59d5266 - (in the future: 8 months later) 元宵节 ― Tom Xue\n>> * b5308da - (in the future: 7 months later) 除夕 ― Tom Xue\n>> ...\n>\n> I was re-reading the backlog and after looking at it again, I do not\n> think what the patch tries to do is a bad thing.  There are changes\n> I want to see _how_ it is done, though.\n>\n> Especially, the duplication of the exact same logic in the future\n> and in the past is an unmaintainable mess.\n>\n> I have queued a replacement in 'pu'.\n"}]}