From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Alex Riesen <raa.lkml@gmail.com>,
git@vger.kernel.org
Subject: [PATCH v2 4/4] fix approxidate parsing of relative months and years
Date: Sun, 30 Aug 2009 22:31:42 -0400 [thread overview]
Message-ID: <20090831023142.GD5507@coredump.intra.peff.net> (raw)
In-Reply-To: <20090831022228.GA4833@coredump.intra.peff.net>
These were broken by b5373e9. The problem is that the code
marks the month and year with "-1" for "we don't know it
yet", but the month and year code paths were not adjusted to
fill in the current time before doing their calculations
(whereas other units follow a different code path and are
fine).
Signed-off-by: Jeff King <peff@peff.net>
---
This one is new from the last series, as it fixes bugs only found in
lt/approxidate.
date.c | 5 ++++-
t/t0006-date.sh | 4 ++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/date.c b/date.c
index 8e57e5e..e9ee4aa 100644
--- a/date.c
+++ b/date.c
@@ -857,7 +857,9 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
}
if (match_string(date, "months") >= 5) {
- int n = tm->tm_mon - *num;
+ int n;
+ update_tm(tm, now, 0); /* fill in date fields if needed */
+ n = tm->tm_mon - *num;
*num = 0;
while (n < 0) {
n += 12;
@@ -868,6 +870,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
}
if (match_string(date, "years") >= 4) {
+ update_tm(tm, now, 0); /* fill in date fields if needed */
tm->tm_year -= *num;
*num = 0;
return end;
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 02cd565..a4d8fa8 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -53,8 +53,8 @@ check_approxidate 10.minutes.ago '2009-08-30 19:10:00'
check_approxidate yesterday '2009-08-29 19:20:00'
check_approxidate 3.days.ago '2009-08-27 19:20:00'
check_approxidate 3.weeks.ago '2009-08-09 19:20:00'
-check_approxidate 3.months.ago '2009-05-30 19:20:00' failure
-check_approxidate 2.years.3.months.ago '2007-05-30 19:20:00' failure
+check_approxidate 3.months.ago '2009-05-30 19:20:00'
+check_approxidate 2.years.3.months.ago '2007-05-30 19:20:00'
check_approxidate '6am yesterday' '2009-08-29 06:00:00'
check_approxidate '6pm yesterday' '2009-08-29 18:00:00'
--
1.6.4.2.373.g5881fd
next prev parent reply other threads:[~2009-08-31 2:31 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-27 23:39 [PATCH] Round-down years in "years+months" relative date view David Reiss
2009-08-28 6:05 ` Jeff King
2009-08-28 7:58 ` Alex Riesen
2009-08-28 15:02 ` Jeff King
2009-08-28 17:00 ` Alex Riesen
2009-08-28 17:15 ` Jeff King
2009-08-28 18:21 ` Alex Riesen
2009-08-28 22:01 ` A Large Angry SCM
2009-08-28 17:28 ` Nicolas Pitre
2009-08-28 18:01 ` Jeff King
2009-08-28 18:27 ` Alex Riesen
2009-08-28 18:39 ` Jeff King
2009-08-28 18:42 ` Alex Riesen
2009-08-28 18:49 ` Alex Riesen
2009-08-28 19:00 ` Nicolas Pitre
2009-08-28 19:08 ` Alex Riesen
2009-08-28 19:27 ` Nicolas Pitre
2009-08-28 19:49 ` Alex Riesen
2009-08-28 20:01 ` Nicolas Pitre
2009-08-28 19:03 ` Alex Riesen
2009-08-28 19:15 ` Jeff King
2009-08-28 19:20 ` Alex Riesen
2009-08-28 19:33 ` Alex Riesen
2009-08-28 20:52 ` [PATCH] Allow testing of _relative family of time formatting and parsing functions Alex Riesen
2009-08-28 20:54 ` Alex Riesen
2009-08-29 21:46 ` Junio C Hamano
2009-08-30 7:25 ` Alex Riesen
2009-08-30 7:51 ` Jeff King
2009-08-30 8:10 ` Alex Riesen
2009-08-30 9:13 ` [PATCH 1/2] Add date formatting and parsing functions relative to a given time Alex Riesen
2009-08-30 9:15 ` [PATCH 2/2] Allow testing of _relative family of time formatting and parsing functions Alex Riesen
2009-08-30 9:15 ` [PATCH 1/2] Add date formatting and parsing functions relative to a given time Jeff King
2009-08-30 9:36 ` Jeff King
2009-08-30 9:56 ` Alex Riesen
2009-08-30 10:08 ` Jeff King
2009-08-30 11:17 ` Alex Riesen
2009-08-30 21:43 ` [PATCH 1/3] " Jeff King
2009-08-30 21:51 ` Jeff King
2009-08-31 2:22 ` Jeff King
2009-08-31 2:26 ` [PATCH v2 1/4] " Jeff King
2009-08-31 6:08 ` Alex Riesen
2009-08-31 2:26 ` [PATCH v2 2/4] refactor test-date interface Jeff King
2009-08-31 2:30 ` [PATCH v2 3/4] tests: add date printing and parsing tests Jeff King
2009-09-01 3:03 ` Jeff King
2009-08-31 2:31 ` Jeff King [this message]
2009-08-30 21:46 ` [PATCH 2/3] refactor test-date interface Jeff King
2009-08-30 21:47 ` [PATCH 3/3] tests: add date printing and parsing tests Jeff King
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=20090831023142.GD5507@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=raa.lkml@gmail.com \
--cc=torvalds@linux-foundation.org \
/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).