Skip to content

Commit

Permalink
pass TIME_DATE_NOW to approxidate future-check
Browse files Browse the repository at this point in the history
The approxidate functions accept an extra "now" parameter to
avoid calling time() themselves. We use this in our test
suite to make sure we have a consistent time for computing
relative dates. However, deep in the bowels of approxidate,
we also call time() to check whether possible dates are far
in the future. Let's make sure that the "now" override makes
it to that spot, too, so we can consistently test that
feature.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Nov 13, 2014
1 parent 6c4ab27 commit 073281e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
return 0;
}

static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
static int match_multi_number(unsigned long num, char c, const char *date,
char *end, struct tm *tm, time_t now)
{
time_t now;
struct tm now_tm;
struct tm *refuse_future;
long num2, num3;
Expand All @@ -424,7 +424,8 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
case '-':
case '/':
case '.':
now = time(NULL);
if (!now)
now = time(NULL);
refuse_future = NULL;
if (gmtime_r(&now, &now_tm))
refuse_future = &now_tm;
Expand Down Expand Up @@ -504,7 +505,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
case '/':
case '-':
if (isdigit(end[1])) {
int match = match_multi_number(num, *end, date, end, tm);
int match = match_multi_number(num, *end, date, end, tm, 0);
if (match)
return match;
}
Expand Down Expand Up @@ -1000,7 +1001,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
return end;
}

static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
time_t now)
{
char *end;
unsigned long number = strtoul(date, &end, 10);
Expand All @@ -1011,7 +1013,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
case '/':
case '-':
if (isdigit(end[1])) {
int match = match_multi_number(number, *end, date, end, tm);
int match = match_multi_number(number, *end, date, end,
tm, now);
if (match)
return date + match;
}
Expand Down Expand Up @@ -1074,7 +1077,7 @@ static unsigned long approxidate_str(const char *date,
date++;
if (isdigit(c)) {
pending_number(&tm, &number);
date = approxidate_digit(date-1, &tm, &number);
date = approxidate_digit(date-1, &tm, &number, time_sec);
touched = 1;
continue;
}
Expand Down

0 comments on commit 073281e

Please sign in to comment.