date.c: s/is_date/set_date/

The function is_date, confusingly also set tm_year. tm_mon, and tm_mday
after validating input.

Rename to set_date to reflect its real usage.

Also, change return value is 0 on success and -1 on failure following
our convention on function do some real work.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Đoàn Trần Công Danh
2020-04-23 20:52:38 +07:00
committed by Junio C Hamano
parent efe3874640
commit c933b28d87

22
date.c
View File

@ -497,7 +497,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
return skip_alpha(date); return skip_alpha(date);
} }
static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm) static int set_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm)
{ {
if (month > 0 && month < 13 && day > 0 && day < 32) { if (month > 0 && month < 13 && day > 0 && day < 32) {
struct tm check = *tm; struct tm check = *tm;
@ -518,9 +518,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
else if (year < 38) else if (year < 38)
r->tm_year = year + 100; r->tm_year = year + 100;
else else
return 0; return -1;
if (!now_tm) if (!now_tm)
return 1; return 0;
specified = tm_to_time_t(r); specified = tm_to_time_t(r);
@ -529,14 +529,14 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
* sure it is not later than ten days from now... * sure it is not later than ten days from now...
*/ */
if ((specified != -1) && (now + 10*24*3600 < specified)) if ((specified != -1) && (now + 10*24*3600 < specified))
return 0; return -1;
tm->tm_mon = r->tm_mon; tm->tm_mon = r->tm_mon;
tm->tm_mday = r->tm_mday; tm->tm_mday = r->tm_mday;
if (year != -1) if (year != -1)
tm->tm_year = r->tm_year; tm->tm_year = r->tm_year;
return 1; return 0;
} }
return 0; return -1;
} }
static int match_multi_number(timestamp_t num, char c, const char *date, static int match_multi_number(timestamp_t num, char c, const char *date,
@ -575,10 +575,10 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
if (num > 70) { if (num > 70) {
/* yyyy-mm-dd? */ /* yyyy-mm-dd? */
if (is_date(num, num2, num3, NULL, now, tm)) if (set_date(num, num2, num3, NULL, now, tm) == 0)
break; break;
/* yyyy-dd-mm? */ /* yyyy-dd-mm? */
if (is_date(num, num3, num2, NULL, now, tm)) if (set_date(num, num3, num2, NULL, now, tm) == 0)
break; break;
} }
/* Our eastern European friends say dd.mm.yy[yy] /* Our eastern European friends say dd.mm.yy[yy]
@ -586,14 +586,14 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
* mm/dd/yy[yy] form only when separator is not '.' * mm/dd/yy[yy] form only when separator is not '.'
*/ */
if (c != '.' && if (c != '.' &&
is_date(num3, num, num2, refuse_future, now, tm)) set_date(num3, num, num2, refuse_future, now, tm) == 0)
break; break;
/* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */ /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */
if (is_date(num3, num2, num, refuse_future, now, tm)) if (set_date(num3, num2, num, refuse_future, now, tm) == 0)
break; break;
/* Funny European mm.dd.yy */ /* Funny European mm.dd.yy */
if (c == '.' && if (c == '.' &&
is_date(num3, num, num2, refuse_future, now, tm)) set_date(num3, num, num2, refuse_future, now, tm) == 0)
break; break;
return 0; return 0;
} }