From c933b28d87062a0c68de298900b9060f577f865a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Thu, 23 Apr 2020 20:52:38 +0700 Subject: date.c: s/is_date/set_date/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- date.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/date.c b/date.c index b0d9a8421d..b67c5abe24 100644 --- a/date.c +++ b/date.c @@ -497,7 +497,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset) 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) { 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) r->tm_year = year + 100; else - return 0; + return -1; if (!now_tm) - return 1; + return 0; 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... */ if ((specified != -1) && (now + 10*24*3600 < specified)) - return 0; + return -1; tm->tm_mon = r->tm_mon; tm->tm_mday = r->tm_mday; if (year != -1) 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, @@ -575,10 +575,10 @@ static int match_multi_number(timestamp_t num, char c, const char *date, if (num > 70) { /* yyyy-mm-dd? */ - if (is_date(num, num2, num3, NULL, now, tm)) + if (set_date(num, num2, num3, NULL, now, tm) == 0) break; /* yyyy-dd-mm? */ - if (is_date(num, num3, num2, NULL, now, tm)) + if (set_date(num, num3, num2, NULL, now, tm) == 0) break; } /* 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 '.' */ if (c != '.' && - is_date(num3, num, num2, refuse_future, now, tm)) + set_date(num3, num, num2, refuse_future, now, tm) == 0) break; /* 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; /* Funny European mm.dd.yy */ if (c == '.' && - is_date(num3, num, num2, refuse_future, now, tm)) + set_date(num3, num, num2, refuse_future, now, tm) == 0) break; return 0; } -- cgit v1.2.3