pass TIME_DATE_NOW to approxidate future-check

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>

Jeff King committed Nov 13, 2014 at 06:04 UTC 073281e2aea7177e27de8a46c5463e2f83833412
1 file changed +10 -7
date.c
+10 -7
@@ -396,9 +396,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
396 return 0;
397 }
398
399 -static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
399 +static int match_multi_number(unsigned long num, char c, const char *date,
400 + char *end, struct tm *tm, time_t now)
401 {
401 - time_t now;
402 struct tm now_tm;
403 struct tm *refuse_future;
404 long num2, num3;
@@ -424,7 +424,8 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
424 case '-':
425 case '/':
426 case '.':
427 - now = time(NULL);
427 + if (!now)
428 + now = time(NULL);
429 refuse_future = NULL;
430 if (gmtime_r(&now, &now_tm))
431 refuse_future = &now_tm;
@@ -504,7 +505,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
505 case '/':
506 case '-':
507 if (isdigit(end[1])) {
507 - int match = match_multi_number(num, *end, date, end, tm);
508 + int match = match_multi_number(num, *end, date, end, tm, 0);
509 if (match)
510 return match;
511 }
@@ -1000,7 +1001,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
1001 return end;
1002 }
1003
1003 -static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
1004 +static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
1005 + time_t now)
1006 {
1007 char *end;
1008 unsigned long number = strtoul(date, &end, 10);
@@ -1011,7 +1013,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
1013 case '/':
1014 case '-':
1015 if (isdigit(end[1])) {
1014 - int match = match_multi_number(number, *end, date, end, tm);
1016 + int match = match_multi_number(number, *end, date, end,
1017 + tm, now);
1018 if (match)
1019 return date + match;
1020 }
@@ -1074,7 +1077,7 @@ static unsigned long approxidate_str(const char *date,
1077 date++;
1078 if (isdigit(c)) {
1079 pending_number(&tm, &number);
1077 - date = approxidate_digit(date-1, &tm, &number);
1080 + date = approxidate_digit(date-1, &tm, &number, time_sec);
1081 touched = 1;
1082 continue;
1083 }