From patchwork Mon Dec 31 00:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stephen P. Smith" X-Patchwork-Id: 10745259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B05301874 for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EBBA28AC0 for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9337128AC1; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E040328ACB for ; Mon, 31 Dec 2018 00:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726835AbeLaAbx (ORCPT ); Sun, 30 Dec 2018 19:31:53 -0500 Received: from fed1rmfepo201.cox.net ([68.230.241.146]:44423 "EHLO fed1rmfepo201.cox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725938AbeLaAbw (ORCPT ); Sun, 30 Dec 2018 19:31:52 -0500 Received: from fed1rmimpo306.cox.net ([68.230.241.174]) by fed1rmfepo201.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20181231003151.EBEV4108.fed1rmfepo201.cox.net@fed1rmimpo306.cox.net> for ; Sun, 30 Dec 2018 19:31:51 -0500 Received: from thunderbird.smith.home (localhost [127.0.0.1]) by thunderbird.smith.home (Postfix) with ESMTP id 8E6F6B837F8; Sun, 30 Dec 2018 17:31:50 -0700 (MST) X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A090207.5C296377.0021,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=2.3 cv=Y4NMTSWN c=1 sm=1 tr=0 a=BlDZPKRk22kUaIvSBqmi8w==:117 a=BlDZPKRk22kUaIvSBqmi8w==:17 a=2ur7OfE09M0A:10 a=Z4Rwk6OoAAAA:8 a=ybZZDoGAAAAA:8 a=kviXuzpPAAAA:8 a=4XSfByAG1AGq6XVSogIA:9 a=HkZW87K1Qel5hWWM3VKY:22 a=0RhZnL1DYvcuLYC8JZ5M:22 a=qrIFiuKZe2vaD64auk6j:22 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (LOGIN) smtp.auth=ischis2@cox.net From: "Stephen P. Smith" To: git@vger.kernel.org Cc: Linus Torvalds , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , "Stephen P . Smith" Subject: [PATCH 1/3] Add 'human' date format Date: Sun, 30 Dec 2018 17:31:48 -0700 Message-Id: <20181231003150.8031-2-ischis2@cox.net> X-Mailer: git-send-email 2.20.1.2.gb21ebb671b In-Reply-To: <20181231003150.8031-1-ischis2@cox.net> References: <20181231003150.8031-1-ischis2@cox.net> Reply-To: alpine.LFD.2.21.999.1807071502260.18818@i7.lan MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Linus Torvalds This adds --date=human, which skips the timezone if it matches the current time-zone, and doesn't print the whole date if that matches (ie skip printing year for dates that are "this year", but also skip the whole date itself if it's in the last few days and we can just say what weekday it was). For really recent dates (same day), use the relative date stamp, while for old dates (year doesn't match), don't bother with time and timezone. Also add 'auto' date mode, which defaults to human if we're using the pager. So you can do git config --add log.date auto and your "git log" commands will show the human-legible format unless you're scripting things. Note that this time format still shows the timezone for recent enough events (but not so recent that they show up as relative dates). You can combine it with the "-local" suffix to never show timezones for an even more simplified view. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano Signed-off-by: Stephen P. Smith --- builtin/blame.c | 4 ++ cache.h | 1 + date.c | 130 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 115 insertions(+), 20 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 6d798f9939..f684e31d82 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -925,6 +925,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix) */ blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */ break; + case DATE_HUMAN: + /* If the year is shown, no time is shown */ + blame_date_width = sizeof("Thu Oct 19 16:00"); + break; case DATE_NORMAL: blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700"); break; diff --git a/cache.h b/cache.h index ca36b44ee0..c4396ebaa6 100644 --- a/cache.h +++ b/cache.h @@ -1439,6 +1439,7 @@ extern struct object *peel_to_type(const char *name, int namelen, enum date_mode_type { DATE_NORMAL = 0, + DATE_HUMAN, DATE_RELATIVE, DATE_SHORT, DATE_ISO8601, diff --git a/date.c b/date.c index 9bc15df6f9..a8d50eb206 100644 --- a/date.c +++ b/date.c @@ -77,22 +77,16 @@ static struct tm *time_to_tm_local(timestamp_t time) } /* - * What value of "tz" was in effect back then at "time" in the - * local timezone? + * Fill in the localtime 'struct tm' for the supplied time, + * and return the local tz. */ -static int local_tzoffset(timestamp_t time) +static int local_time_tzoffset(time_t t, struct tm *tm) { - time_t t, t_local; - struct tm tm; + time_t t_local; int offset, eastwest; - if (date_overflows(time)) - die("Timestamp too large for this system: %"PRItime, time); - - t = (time_t)time; - localtime_r(&t, &tm); - t_local = tm_to_time_t(&tm); - + localtime_r(&t, tm); + t_local = tm_to_time_t(tm); if (t_local == -1) return 0; /* error; just use +0000 */ if (t_local < t) { @@ -107,6 +101,20 @@ static int local_tzoffset(timestamp_t time) return offset * eastwest; } +/* + * What value of "tz" was in effect back then at "time" in the + * local timezone? + */ +static int local_tzoffset(timestamp_t time) +{ + struct tm tm; + + if (date_overflows(time)) + die("Timestamp too large for this system: %"PRItime, time); + + return local_time_tzoffset((time_t)time, &tm); +} + void show_date_relative(timestamp_t time, int tz, const struct timeval *now, struct strbuf *timebuf) @@ -191,9 +199,80 @@ struct date_mode *date_mode_from_type(enum date_mode_type type) return &mode; } +static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local) +{ + struct { + unsigned int year:1, + date:1, + wday:1, + time:1, + seconds:1, + tz:1; + } hide = { 0 }; + + hide.tz = local || tz == human_tz; + hide.year = tm->tm_year == human_tm->tm_year; + if (hide.year) { + if (tm->tm_mon == human_tm->tm_mon) { + if (tm->tm_mday > human_tm->tm_mday) { + /* Future date: think timezones */ + } else if (tm->tm_mday == human_tm->tm_mday) { + hide.date = hide.wday = 1; + } else if (tm->tm_mday + 5 > human_tm->tm_mday) { + /* Leave just weekday if it was a few days ago */ + hide.date = 1; + } + } + } + + /* Show "today" times as just relative times */ + if (hide.wday) { + struct timeval now; + gettimeofday(&now, NULL); + show_date_relative(time, tz, &now, buf); + return; + } + + /* + * Always hide seconds for human-readable. + * Hide timezone if showing date. + * Hide weekday and time if showing year. + * + * The logic here is two-fold: + * (a) only show details when recent enough to matter + * (b) keep the maximum length "similar", and in check + */ + if (human_tm->tm_year) { + hide.seconds = 1; + hide.tz |= !hide.date; + hide.wday = hide.time = !hide.year; + } + + if (!hide.wday) + strbuf_addf(buf, "%.3s ", weekday_names[tm->tm_wday]); + if (!hide.date) + strbuf_addf(buf, "%.3s %d ", month_names[tm->tm_mon], tm->tm_mday); + + /* Do we want AM/PM depending on locale? */ + if (!hide.time) { + strbuf_addf(buf, "%02d:%02d", tm->tm_hour, tm->tm_min); + if (!hide.seconds) + strbuf_addf(buf, ":%02d", tm->tm_sec); + } else + strbuf_rtrim(buf); + + if (!hide.year) + strbuf_addf(buf, " %d", tm->tm_year + 1900); + + if (!hide.tz) + strbuf_addf(buf, " %+05d", tz); +} + const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) { struct tm *tm; + struct tm human_tm = { 0 }; + int human_tz = -1; static struct strbuf timebuf = STRBUF_INIT; if (mode->type == DATE_UNIX) { @@ -202,6 +281,15 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) return timebuf.buf; } + if (mode->type == DATE_HUMAN) { + struct timeval now; + + gettimeofday(&now, NULL); + + /* Fill in the data for "current time" in human_tz and human_tm */ + human_tz = local_time_tzoffset(now.tv_sec, &human_tm); + } + if (mode->local) tz = local_tzoffset(time); @@ -258,14 +346,7 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz, !mode->local); else - strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d", - weekday_names[tm->tm_wday], - month_names[tm->tm_mon], - tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, - tm->tm_year + 1900, - mode->local ? 0 : ' ', - tz); + show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, mode->local); return timebuf.buf; } @@ -802,6 +883,11 @@ int parse_date(const char *date, struct strbuf *result) return 0; } +static int auto_date_style(void) +{ + return (isatty(1) || pager_in_use()) ? DATE_HUMAN : DATE_NORMAL; +} + static enum date_mode_type parse_date_type(const char *format, const char **end) { if (skip_prefix(format, "relative", end)) @@ -819,6 +905,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) return DATE_SHORT; if (skip_prefix(format, "default", end)) return DATE_NORMAL; + if (skip_prefix(format, "human", end)) + return DATE_HUMAN; + if (skip_prefix(format, "auto", end)) + return auto_date_style(); if (skip_prefix(format, "raw", end)) return DATE_RAW; if (skip_prefix(format, "unix", end)) From patchwork Mon Dec 31 00:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stephen P. Smith" X-Patchwork-Id: 10745253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44B7013BF for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E29F28AC0 for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC2F328AD0; Mon, 31 Dec 2018 00:32:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 735F428AC0 for ; Mon, 31 Dec 2018 00:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbeLaAbw (ORCPT ); Sun, 30 Dec 2018 19:31:52 -0500 Received: from fed1rmfepo101.cox.net ([68.230.241.143]:34263 "EHLO fed1rmfepo101.cox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbeLaAbw (ORCPT ); Sun, 30 Dec 2018 19:31:52 -0500 Received: from fed1rmimpo110.cox.net ([68.230.241.159]) by fed1rmfepo101.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20181231003151.YKSV4101.fed1rmfepo101.cox.net@fed1rmimpo110.cox.net> for ; Sun, 30 Dec 2018 19:31:51 -0500 Received: from thunderbird.smith.home (localhost [127.0.0.1]) by thunderbird.smith.home (Postfix) with ESMTP id A1970B837FB; Sun, 30 Dec 2018 17:31:50 -0700 (MST) X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A090207.5C296377.0027,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=2.3 cv=L8upvNb8 c=1 sm=1 tr=0 a=BlDZPKRk22kUaIvSBqmi8w==:117 a=BlDZPKRk22kUaIvSBqmi8w==:17 a=2ur7OfE09M0A:10 a=WDhBSedXqNQA:10 a=kviXuzpPAAAA:8 a=Zg4XqIe21ZXrWr11gN8A:9 a=qrIFiuKZe2vaD64auk6j:22 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (LOGIN) smtp.auth=ischis2@cox.net From: "Stephen P. Smith" To: git@vger.kernel.org Cc: Linus Torvalds , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , "Stephen P . Smith" Subject: [PATCH 2/3] Add 'human' date format documentation Date: Sun, 30 Dec 2018 17:31:49 -0700 Message-Id: <20181231003150.8031-3-ischis2@cox.net> X-Mailer: git-send-email 2.20.1.2.gb21ebb671b In-Reply-To: <20181231003150.8031-1-ischis2@cox.net> References: <20181231003150.8031-1-ischis2@cox.net> Reply-To: alpine.LFD.2.21.999.1807071502260.18818@i7.lan MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Display date and time information in a format similar to how people write dates in other contexts. If the year isn't specified then, the reader infers the date is given is in the current year. By not displaying the redundant information, the reader concentrates on the information that is different. The patch reports relative dates based on information inferred from the date on the machine running the git command at the time the command is executed. While the format is more useful to humans by dropping inferred information, there is nothing that makes it actually human. If the 'relative' date format wasn't already implemented then using 'relative' would have been appropriate. Signed-off-by: Stephen P. Smith --- Documentation/rev-list-options.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index bab5f50b17..b491c3b999 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -835,6 +835,14 @@ Note that the `-local` option does not affect the seconds-since-epoch value (which is always measured in UTC), but does switch the accompanying timezone value. + +`--date=human` shows the timezone if it matches the current time-zone, +and doesn't print the whole date if that matches (ie skip printing +year for dates that are "this year", but also skip the whole date +itself if it's in the last few days and we can just say what weekday +it was). ++ +`--date=auto` defaults to human if we're using the pager. ++ `--date=unix` shows the date as a Unix epoch timestamp (seconds since 1970). As with `--raw`, this is always in UTC and therefore `-local` has no effect. From patchwork Mon Dec 31 00:31:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stephen P. Smith" X-Patchwork-Id: 10745257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89EE86C2 for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77E3728AC0 for ; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C71B28AC1; Mon, 31 Dec 2018 00:32:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C008028ACA for ; Mon, 31 Dec 2018 00:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726873AbeLaAbx (ORCPT ); Sun, 30 Dec 2018 19:31:53 -0500 Received: from fed1rmfepo101.cox.net ([68.230.241.143]:44613 "EHLO fed1rmfepo101.cox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbeLaAbw (ORCPT ); Sun, 30 Dec 2018 19:31:52 -0500 Received: from fed1rmimpo110.cox.net ([68.230.241.159]) by fed1rmfepo101.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20181231003151.YKSX4101.fed1rmfepo101.cox.net@fed1rmimpo110.cox.net> for ; Sun, 30 Dec 2018 19:31:51 -0500 Received: from thunderbird.smith.home (localhost [127.0.0.1]) by thunderbird.smith.home (Postfix) with ESMTP id B7DBDB8380C; Sun, 30 Dec 2018 17:31:50 -0700 (MST) X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A090207.5C296377.0031,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=2.3 cv=L8upvNb8 c=1 sm=1 tr=0 a=BlDZPKRk22kUaIvSBqmi8w==:117 a=BlDZPKRk22kUaIvSBqmi8w==:17 a=2ur7OfE09M0A:10 a=WDhBSedXqNQA:10 a=kviXuzpPAAAA:8 a=61RRfQX-yyrNk2VQgeQA:9 a=qrIFiuKZe2vaD64auk6j:22 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (LOGIN) smtp.auth=ischis2@cox.net From: "Stephen P. Smith" To: git@vger.kernel.org Cc: Linus Torvalds , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , "Stephen P . Smith" Subject: [PATCH 3/3] t0006-date.sh: add `human` date format tests. Date: Sun, 30 Dec 2018 17:31:50 -0700 Message-Id: <20181231003150.8031-4-ischis2@cox.net> X-Mailer: git-send-email 2.20.1.2.gb21ebb671b In-Reply-To: <20181231003150.8031-1-ischis2@cox.net> References: <20181231003150.8031-1-ischis2@cox.net> Reply-To: alpine.LFD.2.21.999.1807071502260.18818@i7.lan MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The `human` date format varies based on two inputs: the date in the reference time which is constant and the local computers date which varies. Using hardcoded test expected output dates would require holding the local machines date and time constant which is not desireable. Alternatively, letting the local date vary, which is the normal situation, implies that the tests would be checking for formating changes based on on a ref date relative to the local computers time. When using `human` several fields are suppressed depending on the time difference between the reference date and the local computer date. In cases where the difference is less than a year, the year field is supppressed. If the time is less than a day; the month and year is suppressed. Test using a regular expression to verify that fields that are expected to be suppressed are not displayed. Signed-off-by: Stephen P. Smith --- t/t0006-date.sh | 24 ++++++++++++++++++++++++ t/t4202-log.sh | 24 ++++++++++++++++++++++++ t/t7007-show.sh | 25 +++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/t/t0006-date.sh b/t/t0006-date.sh index ffb2975e48..f208a80867 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -40,6 +40,16 @@ check_show () { ' } +check_human_date () { + time=$1 + expect=$2 + test_expect_success "check date ($format:$time)" ' + echo "$time -> $expect" >expect && + TZ=${zone:-$TZ} test-tool date show:"$format" "$time" >actual && + grep "$expect" actual + ' +} + # arbitrary but sensible time for examples TIME='1466000000 +0200' check_show iso8601 "$TIME" '2016-06-15 16:13:20 +0200' @@ -52,6 +62,20 @@ check_show unix "$TIME" '1466000000' check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000' check_show raw-local "$TIME" '1466000000 +0000' check_show unix-local "$TIME" '1466000000' +check_show human "$TIME" 'Jun 15 2016' + +# Subtract some known constant time and look for expected field format +TODAY_REGEX='5 hours ago' +THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]' +MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]' +check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago +check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago +check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago +check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago +check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago +check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago +check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago +check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago check_show 'format:%z' "$TIME" '+0200' check_show 'format-local:%z' "$TIME" '+0000' diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 819c24d10e..d7f3b73650 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1707,4 +1707,28 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' ' test_must_fail git log --exclude-promisor-objects source-a ' +check_human_date() { + commit_date=$1 + expect=$2 + test_expect_success "$commit_date" " + echo $expect $commit_date >dates && + git add dates && + git commit -m 'Expect String' --date=\"$commit_date\" dates && + git log -1 --date=human | grep \"^Date:\" >actual && + grep \"$expect\" actual +" +} + +TODAY_REGEX='[A-Z][a-z][a-z] [012][0-9]:[0-6][0-9] .0200' +THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]' +MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]' +check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago +check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago +check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago +check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago +check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago +check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago +check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago +check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago + test_done diff --git a/t/t7007-show.sh b/t/t7007-show.sh index 42d3db6246..0a0334a8b5 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -128,4 +128,29 @@ test_expect_success 'show --graph is forbidden' ' test_must_fail git show --graph HEAD ' +check_human_date() { + commit_date=$1 + expect=$2 + test_expect_success "$commit_date" " + echo $expect $commit_date >dates && + git add dates && + git commit -m 'Expect String' --date=\"$commit_date\" dates && + git show --date=human | grep \"^Date:\" >actual && + grep \"$expect\" actual +" +} + +TODAY_REGEX='[A-Z][a-z][a-z] [012][0-9]:[0-6][0-9] .0200' +THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]' +MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]' +check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago +check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago +check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago +check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago +check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago +check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago +check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago +check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago + + test_done