提交 04950c71 编写于 作者: J Junio C Hamano

Merge branch 'jk/approxidate-avoid-y-d-m-over-future-dates'

Traditionally we tried to avoid interpreting date strings given by
the user as future dates, e.g. GIT_COMMITTER_DATE=2014-12-10 when
used early November 2014 was taken as "October 12, 2014" because it
is likely that a date in the future, December 10, is a mistake.

Loosen this and do not tiebreak by future-ness of the date when

(1) ISO-like format is used, and
(2) the string can make sense interpreted as both y-m-d and y-d-m.

* jk/approxidate-avoid-y-d-m-over-future-dates:
  approxidate: allow ISO-like dates far in the future
  pass TIME_DATE_NOW to approxidate future-check
...@@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, ...@@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
return 0; 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 now_tm;
struct tm *refuse_future; struct tm *refuse_future;
long num2, num3; long num2, num3;
...@@ -433,17 +433,18 @@ static int match_multi_number(unsigned long num, char c, const char *date, char ...@@ -433,17 +433,18 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
case '-': case '-':
case '/': case '/':
case '.': case '.':
now = time(NULL); if (!now)
now = time(NULL);
refuse_future = NULL; refuse_future = NULL;
if (gmtime_r(&now, &now_tm)) if (gmtime_r(&now, &now_tm))
refuse_future = &now_tm; refuse_future = &now_tm;
if (num > 70) { if (num > 70) {
/* yyyy-mm-dd? */ /* yyyy-mm-dd? */
if (is_date(num, num2, num3, refuse_future, now, tm)) if (is_date(num, num2, num3, NULL, now, tm))
break; break;
/* yyyy-dd-mm? */ /* yyyy-dd-mm? */
if (is_date(num, num3, num2, refuse_future, now, tm)) if (is_date(num, num3, num2, NULL, now, tm))
break; break;
} }
/* Our eastern European friends say dd.mm.yy[yy] /* Our eastern European friends say dd.mm.yy[yy]
...@@ -513,7 +514,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt ...@@ -513,7 +514,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
case '/': case '/':
case '-': case '-':
if (isdigit(end[1])) { 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) if (match)
return match; return match;
} }
...@@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm ...@@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
return end; 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; char *end;
unsigned long number = strtoul(date, &end, 10); unsigned long number = strtoul(date, &end, 10);
...@@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num) ...@@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
case '/': case '/':
case '-': case '-':
if (isdigit(end[1])) { 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) if (match)
return date + match; return date + match;
} }
...@@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date, ...@@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date,
date++; date++;
if (isdigit(c)) { if (isdigit(c)) {
pending_number(&tm, &number); pending_number(&tm, &number);
date = approxidate_digit(date-1, &tm, &number); date = approxidate_digit(date-1, &tm, &number, time_sec);
touched = 1; touched = 1;
continue; continue;
} }
......
...@@ -82,4 +82,7 @@ check_approxidate 'Jun 6, 5AM' '2009-06-06 05:00:00' ...@@ -82,4 +82,7 @@ check_approxidate 'Jun 6, 5AM' '2009-06-06 05:00:00'
check_approxidate '5AM Jun 6' '2009-06-06 05:00:00' check_approxidate '5AM Jun 6' '2009-06-06 05:00:00'
check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00' check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
check_approxidate '2008-12-01' '2008-12-01 19:20:00'
check_approxidate '2009-12-01' '2009-12-01 19:20:00'
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册